English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML link media attribute

The link media attribute specifies the type of media the target resource is intended for/Optimized for devices, this attribute is typically used with CSS stylesheets to specify different styles for different media types.

 HTML <link> tag

Online Example

Two different stylesheets for two different media types (screen and print):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8>
<title>HTML <link> hreflang Attribute Usage-基础教程(oldtoolbag.com)</title>/title>
<link rel="stylesheet" type="text/css" href="demo_screen.css">
<link rel="stylesheet" type="text/css" href="demo_print.css" media="print">
</head>
<body>
<h1>oldtoolbag.com Example/h1>
<p><a href="tryhtml_link_media.html" target="_blank">Click here</a>/<a href="#" onclick="window.open('tryit.html'); return false;">Open this page in a new window (without the tryit section).</a>/p>
<p>If you print this page or open it in the print preview, you will see that it uses the 'media="print"' stylesheet for styling. The 'Print' stylesheet contains black text on a white background.</p>/p>
</body>
</html>
Test to see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the media attribute.

Definition and Usage

The media attribute specifies the type of media for which the target resource is intended/The device is optimized.

This attribute is usually used with CSS style sheets to specify different styles for different media types.

The media attribute can accept multiple values.

HTML 4.01 with HTML5differences

The media attribute now supports more values.

Syntax

<link media="value>

Possible operators

ValueDescription
andDefine an AND operator.
notDefine a NOT operator.
,Define an OR operator.

device

ValueDescription
allDefault. Applies to all devices.
auralVoice synthesizer.
brailleBraille feedback device.
handheldHandheld devices (small screen, limited bandwidth).
projectionProjector.
printPrint preview mode/Print page.
screenComputer screen.
ttyTeletype and similar media using a monospaced character grid.
tvTelevision type devices (low resolution, limited scrolling ability).

Value

ValueDescription
widthDefine the width of the target display area
Can use "min-" and "max-" prefix.
Example: media="screen and (min-width:500px)"
heightDefine the height of the target display area
Can use "min-" and "max-" prefix.
Example: media="screen and (max-height:700px)"
device-widthSpecifies the target display/The width of the paper.
Can use "min-" and "max-" prefix.
Example: media="screen and (device-width:500px)"
device-heightSpecifies the target display/The height of the paper.
Can use "min-" and "max-" prefix.
Example: media="screen and (device-height:500px)"
orientationSpecifies the target display/The orientation of the paper.
Possible values: "portrait" or "landscape".
Example: media="all and (orientation: landscape)"
aspect-ratioDefine the width of the target display area/height ratio.
Can use "min-" and "max-" prefix.
Example: media="screen and (aspect-ratio:16/9)"
device-aspect-ratioSpecifies the target display/The device of the paper-width/device-height ratio.
Can use "min-" and "max-" prefix.
Example: media="screen and (aspect-ratio:16/9)"
colorDefine the target display's bits/color.
Can use "min-" and "max-" prefix.
Example: media="screen and (color:3)"
color-indexSpecifies the number of colors the target display can handle.
Can use "min-" and "max-" prefix.
Example: media="screen and (min-color-index:256)"
monochromeSpecifies the bits in the monochrome frame buffer/pixel.
Can use "min-" and "max-" prefix.
Example: media="screen and (monochrome:2)"
resolutionSpecifies the target display/Pixel density of the paper (dpi or dpcm).
Can use "min-" and "max-" prefix.
Example: media="print and (resolution:300dpi)"
scanSpecifies the scanning method of the TV display.
Possible values: "progressive" and "interlace".
Example: media="tv and (scan:interlace)"
gridSpecifies whether the output device is a grid or bitmap.
Possible values:"1" for grid, otherwise for "0".
Example: media="handheld and (grid:1)"
 HTML <link> tag