CSS media queries

  • Revision slug: CSS/Media_queries
  • Revision title: CSS media queries
  • Revision id: 28901
  • Created:
  • Creator: Jonathan_Watt
  • Is current revision? No
  • Comment Add in {min|max}-aspect-ration, which somehow got forgotten; 147 words added

Revision Content

{{ gecko_minversion_header("1.9.1") }}

CSS 3 enhances support for media-dependent style sheets by letting style sheets be more precisely labeled.  A media query consists of a media type and at least one expression that limits the style sheets' scope by using media features, such as width, height, and color.  Media queries let the presentation of content be tailored to a specific range of output devices without having to change the content itself.

Syntax

Media queries consist of a media type and one or more expressions, involving media features, which resolve to either true or false.  The result of the query is true if the media type specified in the media query matches the type of device the document is being displayed on and all expressions in the media query are true.

When a media query is true, the corresponding style sheet is applied following the normal cascading rules.

Logical operators

You can compose complex media queries using logical operators, including not, and, and only.

In addition, you can combine multiple media queries in a comma-separated list; if any of the media queries in the list is true, the associated style sheet is applied.  This is the equivalent of a logical "or" operation.

The not keyword negates the result of the query; "all and (not color)" is true for monochrome devices regardless of media type, for example.

The only keyword will hide style sheets from older browsers that don't support media queries:

<link rel="stylesheet" media="only screen and (color)" href="example.css" />

Pseudo-BNF (for those of you that like that kind of thing)

media_query_list: <media_query> [, <media_query> ]*
media_query: [[only | not]? <media_type> [ and <expression> ]*]
  | <expression> [ and <expression> ]*
expression: ( <media_feature> [: <value>]? )
media_type: all | aural | braille | handheld | print |
  projection | screen | tty | tv | embossed
media_feature: width | min-width | max-width
  | height | min-height | max-height
  | device-width | min-device-width | max-device-width
  | device-height | min-device-height | max-device-height
  | aspect-ratio | min-aspect-ratio | max-aspect-ratio
  | device-aspect-ratio | min-device-aspect-ratio | max-device-aspect-ratio
  | color | min-color | max-color
  | color-index | min-color-index | max-color-index
  | monochrome | min-monochrome | max-monochrome
  | resolution | min-resolution | max-resolution
  | scan | grid

Media queries are case insensitive.  Media queries involving unknown media types are always false.

Note: Parentheses are required around expressions; failing to use them is an error.

Media features

Most media features can be prefixed with "min-" or "max-" to express "greater or equal to" or "less than or equal to" constraints.  This avoids using the "<" and ">" symbols, which would conflict with HTML and XML.  If you use a media feature without specifying a value, the expression resolves to true if the feature's value is non-zero.

Note: If a media feature doesn't apply to the device on which the browser is running, expressions involving that media feature will always be false.  For example, querying the aspect ratio of an aural device will always result in false.

color

Value: {{ Xref_csscolorvalue() }}
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: yes

Indicates the number of bits per color component of the output device.  If the device is not a color device, this value is zero.

Note: If the color components have different numbers of bits per color component, the smallest number is used.  For example, if a display uses 5 bits for blue and red and 6 bits for green, then the device is considered to use 5 bits per color component.  If the device uses indexed colors, the minimum number of bits per color component in the color table is used.

Examples

To apply a style sheet to all color devices:

@media all and (color) { ... }

To apply a style sheet to devices with at least 4 bits per color component:

@media all and (min-color: 4) { ... }

color-index

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: yes

Indicates the number of entries in the color lookup table for the output device.

Examples

To indicate that a style sheet should apply to all devices using indexed color, you can do:

@media all and (color-index) { ... }

To apply a style sheet to indexed color devices with at least 256 colors:

<link rel="stylesheet" media="all and (min-color-index: 256)" href="http://foo.bar.com/stylesheet.css" />

aspect-ratio

Value: integer / integer
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

Describes the aspect ratio of the targeted display area of the output device.  This value consists of two positive integers separated by a slash ("/") character.  This represents the number of horizontal pixels over the number of vertical pixels.

Example

The following selects a special style sheet to use for when the display area is at least as wide as it is high.

@media screen and (min-aspect-ratio: 1/1) { ... }

This selects the style when the aspect ratio is either 1:1 or greater.

device-aspect-ratio

Value: integer / integer
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

Describes the aspect ratio of the output device.  This value consists of two positive integers separated by a slash ("/") character.  This represents the number of horizontal pixels over the number of vertical pixels.

Example

The following selects a special style sheet to use for widescreen displays.

@media screen and (device-aspect-ratio: 16/9), screen and (device-aspect-ratio: 16/10) { ... }

This selects the style when the aspect ratio is either 16:9 or 16:10.

device-height

Value: {{ Xref_csslength() }}
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

Describes the height of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).

Example

To apply a style sheet to a document when displayed on a screen that is less than 800 pixels wide, you can use this:

<link rel="stylesheet" media="screen and (max-device-width: 799px)" />

device-width

Value: {{ Xref_csslength() }}
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

Describes the width of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).

grid

Value: integer
Media: all
Accepts min/max prefixes: no

Determines whether the output device is a grid device or a bitmap device.  If the device is grid-based (such as a tty terminal or a phone display with only one font), the value is 1.  Otherwise it is zero.

Note: Gecko (and therefore Firefox) does not currently support grid devices, so this media feature is not supported.

Example

To apply a style to handheld devices with a 15-character or narrower display:

@media handheld and (grid) and (max-width: 15em) { ... }
Note: The "em" unit has a special meaning for grid devices; since the exact width of an "em" can't be determined, 1em is assumed to be the width of one grid cell horizontally, and the height of one cell vertically.

height

Value: {{ Xref_csslength() }}
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

The height media feature describes the height of the output device's rendering surface (such as the height of the viewport or of the page box on a printer).

Note: As the user resizes the window, Firefox will switch style sheets as appropriate based on media queries using the width and height media features.

monochrome

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: yes

Indicates the number of bits per pixel on a monochrome (greyscale) device.  If the device isn't monochrome, the device's value is 0.

Examples

To apply a style sheet to all monochrome devices:

@media all and (monochrome) { ... }

To apply a style sheet to monochrome devices with at least 8 bits per pixel:

@media all and (min-monochrome: 8) { ... }

orientation

Value: landscape | portrait
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

Indicates whether the device is in landscape (the display is wider than it is tall) or portrait (the display is taller than it is wide) mode.

Example

To apply a style sheet only in portrait oreintation:

@media all and (orientation: portrait) { ... }

resolution

Value: {{ Xref_cssresolution() }}
Media: {{ Xref_cssbitmap() }}
Accepts min/max prefixes: yes

Indicates the resolution (pixel density) of the output device.  The resolution may be specified in either dots per inch (dpi) or dots per centimeter (dpcm).

Example

To apply a style sheet to devices with at least 300 dots per inch of resolution:

@media print and (min-resolution: 300dpi) { ... }

scan

Value: progressiveinterlace
Media: {{ Xref_csstv() }}
Accepts min/max prefixes: no

Describes the scanning process of television output devices.

Note: Gecko (and therefore Firefox) does not currently support the tv media type, so this media feature is likewise unsupported.

Example

To apply a style sheet only to progressive scanning televisions:

@media tv and (scan: progressive) { ... }

width

Value: {{ Xref_csslength() }}
Media: {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}
Accepts min/max prefixes: yes

The width media feature describes the width of the rendering surface of the output device (such as the width of the document window, or the width of the page box on a printer).

Note: As the user resizes the window, Firefox will switch style sheets as appropriate based on media queries using the width and height media features.

Examples

If you want to specify a style sheet for handheld devices, or screen devices with a width greater than 20em, you can use this style sheet:

@media handheld and (min-width: 20em), screen and (min-width: 20em) { ... }

This media query specifies a style sheet that should apply to printed media wider than 8.5 inches:

<link rel="stylesheet" media="print and (min-width: 8.5in)"
    href="http://foo.com/mystyle.css" />

This query specifies a style sheet that is usable when the viewport is between 500 and 800 pixels wide:

@media screen and (min-width: 500px) and (max-width: 800px) { ... }

Mozilla-specific media features

{{ gecko_minversion_header("1.9.2") }}

Mozilla offers several Gecko-specific media features. Some of these may be proposed as official media features.

-moz-images-in-menus

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device allows images to appear in menus, this is 1; otherwise, the value is 0. This corresponds to the {{ cssxref(":-moz-system-metric(images-in-menus)") }} CSS pseudo class.

-moz-mac-graphite-theme

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the user has configured their device to use the "Graphite" appearance on Mac OS X, this is 1. If the user is using the standard blue appearance, or is not on Mac OS X, this is 0.

This corresponds to the {{ cssxref(":-moz-system-metric(mac-graphite-theme)") }} CSS pseudo class.

-moz-maemo-classic

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the user is using Maemo with the original theme, this is 1; if it's using the newer Fremantle theme, this is 0.

This corresponds to the {{ cssxref(":-moz-system-metric(windows-classic)") }} CSS pseudo class.

-moz-scrollbar-end-backward

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device's user interface displays a backward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-end-backward)") }} CSS pseudo class.

-moz-scrollbar-end-forward

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device's user interface displays a forward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-end-backward)") }} CSS pseudo class.

-moz-scrollbar-start-backward

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device's user interface displays a backward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-start-backward)") }} CSS pseudo class.

-moz-scrollbar-start-forward

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device's user interface displays a forward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-start-backward)") }} CSS pseudo class.

-moz-scrollbar-thumb-proportional

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device's user interface displays the thumb of scrollbars proportionally (that is, sized based on the percentage of the document that is visible), this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-thumb-proportional)") }} CSS pseudo class.

-moz-touch-enabled

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the device supports touch events (for a touch screen), this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(touch-enabled)") }} CSS pseudo class.

Example

You might use this to render your buttons slightly larger, for example, if the user is on a touch-screen device, to make them more finger-friendly.

-moz-windows-classic

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the user is using Windows unthemed (in classic mode instead of using uxtheme), this is 1; otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(windows-classic)") }} CSS pseudo class.

-moz-windows-compositor

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the user is using Windows with the DWM compositor, this is 1; otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(windows-compositor)") }} CSS pseudo class.

-moz-windows-default-theme

Value: integer
Media: {{ Xref_cssvisual() }}
Accepts min/max prefixes: no

If the user is currently using one of the default Windows themes (Luna, Royale, Zune, or Aero (including Vista Basic, Vista Advanced, and Aero Glass), this is 1. Otherwise it's 0.

This corresponds to the {{ cssxref(":-moz-system-metric(windows-default-theme)") }} CSS pseudo class.

See also

{{ languages( { "fr": "fr/CSS/Media_queries" } ) }}

Revision Source

<p>{{ gecko_minversion_header("1.9.1") }}</p>
<p>CSS 3 enhances support for media-dependent style sheets by letting style sheets be more precisely labeled.  A media query consists of a media type and at least one expression that limits the style sheets' scope by using media features, such as width, height, and color.  Media queries let the presentation of content be tailored to a specific range of output devices without having to change the content itself.</p>
<h2>Syntax</h2>
<p>Media queries consist of a <a class="internal" href="/en/CSS/@media" title="En/CSS/@media">media type</a> and one or more expressions, involving media features, which resolve to either true or false.  The result of the query is true if the media type specified in the media query matches the type of device the document is being displayed on <strong>and</strong> all expressions in the media query are true.</p>
<p>When a media query is true, the corresponding style sheet is applied following the normal cascading rules.</p>
<h3>Logical operators</h3>
<p>You can compose complex media queries using logical operators, including <code>not</code>, <code>and</code>, and <code>only</code>.</p>
<p>In addition, you can combine multiple media queries in a comma-separated list; if any of the media queries in the list is true, the associated style sheet is applied.  This is the equivalent of a logical "or" operation.</p>
<p>The <code>not</code> keyword negates the result of the query; "<span style="font-family: monospace;">all</span><code> and (not color)</code>" is true for monochrome devices regardless of media type, for example.</p>
<p>The <code>only</code> keyword will hide style sheets from older browsers that don't support media queries:</p>
<pre>&lt;link rel="stylesheet" media="only screen and (color)" href="example.css" /&gt;
</pre>
<h3>Pseudo-BNF (for those of you that like that kind of thing)</h3>
<pre>media_query_list: &lt;media_query&gt; [, &lt;media_query&gt; ]*
media_query: [[only | not]? &lt;media_type&gt; [ and &lt;expression&gt; ]*]
  | &lt;expression&gt; [ and &lt;expression&gt; ]*
expression: ( &lt;media_feature&gt; [: &lt;value&gt;]? )
media_type: all | aural | braille | handheld | print |
  projection | screen | tty | tv | embossed
media_feature: width | min-width | max-width
  | height | min-height | max-height
  | device-width | min-device-width | max-device-width
  | device-height | min-device-height | max-device-height
  | aspect-ratio | min-aspect-ratio | max-aspect-ratio
  | device-aspect-ratio | min-device-aspect-ratio | max-device-aspect-ratio
  | color | min-color | max-color
  | color-index | min-color-index | max-color-index
  | monochrome | min-monochrome | max-monochrome
  | resolution | min-resolution | max-resolution
  | scan | grid</pre>
<p>Media queries are case insensitive.  Media queries involving unknown media types are always false.</p>
<div class="note"><strong>Note:</strong> Parentheses are required around expressions; failing to use them is an error.</div>
<h2>Media features</h2>
<p>Most media features can be prefixed with "min-" or "max-" to express "greater or equal to" or "less than or equal to" constraints.  This avoids using the "&lt;" and "&gt;" symbols, which would conflict with HTML and XML.  If you use a media feature without specifying a value, the expression resolves to true if the feature's value is non-zero.</p>
<div class="note"><strong>Note:</strong> If a media feature doesn't apply to the device on which the browser is running, expressions involving that media feature will always be false.  For example, querying the aspect ratio of an aural device will always result in false.</div>
<h3>color</h3>
<p><strong>Value:</strong> {{ Xref_csscolorvalue() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Indicates the number of bits per color component of the output device.  If the device is not a color device, this value is zero.</p>
<div class="note"><strong>Note:</strong> If the color components have different numbers of bits per color component, the smallest number is used.  For example, if a display uses 5 bits for blue and red and 6 bits for green, then the device is considered to use 5 bits per color component.  If the device uses indexed colors, the minimum number of bits per color component in the color table is used.</div>
<h4>Examples</h4>
<p>To apply a style sheet to all color devices:</p>
<pre>@media all and (color) { ... }
</pre>
<p>To apply a style sheet to devices with at least 4 bits per color component:</p>
<pre>@media all and (min-color: 4) { ... }
</pre>
<h3>color-index</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Indicates the number of entries in the color lookup table for the output device.</p>
<h4>Examples</h4>
<p>To indicate that a style sheet should apply to all devices using indexed color, you can do:</p>
<pre>@media all and (color-index) { ... }
</pre>
<p>To apply a style sheet to indexed color devices with at least 256 colors:</p>
<pre>&lt;link rel="stylesheet" media="all and (min-color-index: 256)" href="http://foo.bar.com/stylesheet.css" /&gt;
</pre>
<h3>aspect-ratio</h3>
<p><strong>Value:</strong> integer / integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Describes the aspect ratio of the targeted display area of the output device.  This value consists of two positive integers separated by a slash ("/") character.  This represents the number of horizontal pixels over the number of vertical pixels.</p>
<h4>Example</h4>
<p>The following selects a special style sheet to use for when the display area is at least as wide as it is high.</p>
<pre>@media screen and (min-aspect-ratio: 1/1) { ... }</pre>
<p>This selects the style when the aspect ratio is either 1:1 or greater.</p>
<h3>device-aspect-ratio</h3>
<p><strong>Value:</strong> integer / integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Describes the aspect ratio of the output device.  This value consists of two positive integers separated by a slash ("/") character.  This represents the number of horizontal pixels over the number of vertical pixels.</p>
<h4>Example</h4>
<p>The following selects a special style sheet to use for widescreen displays.</p>
<pre>@media screen and (device-aspect-ratio: 16/9), screen and (device-aspect-ratio: 16/10) { ... }</pre>
<p>This selects the style when the aspect ratio is either 16:9 or 16:10.</p>
<h3>device-height</h3>
<p><strong>Value:</strong> {{ Xref_csslength() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Describes the height of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).</p>
<h4>Example</h4>
<p>To apply a style sheet to a document when displayed on a screen that is less than 800 pixels wide, you can use this:</p>
<pre>&lt;link rel="stylesheet" media="screen and (max-device-width: 799px)" /&gt;
</pre>
<h3>device-width</h3>
<p><strong>Value:</strong> {{ Xref_csslength() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Describes the width of the output device (meaning the entire screen or page, rather than just the rendering area, such as the document window).</p>
<h3>grid</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> all<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>Determines whether the output device is a grid device or a bitmap device.  If the device is grid-based (such as a tty terminal or a phone display with only one font), the value is 1.  Otherwise it is zero.</p>
<div class="note"><strong>Note:</strong> Gecko (and therefore Firefox) does not currently support grid devices, so this media feature is not supported.</div>
<h4>Example</h4>
<p>To apply a style to handheld devices with a 15-character or narrower display:</p>
<pre>@media handheld and (grid) and (max-width: 15em) { ... }
</pre>
<div class="note"><strong>Note:</strong> The "em" unit has a special meaning for grid devices; since the exact width of an "em" can't be determined, 1em is assumed to be the width of one grid cell horizontally, and the height of one cell vertically.</div>
<h3>height</h3>
<p><strong>Value:</strong> {{ Xref_csslength() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>The <code>height</code> media feature describes the height of the output device's rendering surface (such as the height of the viewport or of the page box on a printer).</p>
<div class="note"><strong>Note:</strong> As the user resizes the window, Firefox will switch style sheets as appropriate based on media queries using the <code>width</code> and <code>height</code> media features.</div>
<h3>monochrome</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Indicates the number of bits per pixel on a monochrome (greyscale) device.  If the device isn't monochrome, the device's value is 0.</p>
<h4>Examples</h4>
<p>To apply a style sheet to all monochrome devices:</p>
<pre>@media all and (monochrome) { ... }
</pre>
<p>To apply a style sheet to monochrome devices with at least 8 bits per pixel:</p>
<pre>@media all and (min-monochrome: 8) { ... }
</pre>
<h3>orientation</h3>
<p><strong>Value:</strong> <code>landscape</code> | <code>portrait</code><br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>Indicates whether the device is in landscape (the display is wider than it is tall) or portrait (the display is taller than it is wide) mode.</p>
<h4>Example</h4>
<p>To apply a style sheet only in portrait oreintation:</p>
<pre>@media all and (orientation: portrait) { ... }</pre>
<h3>resolution</h3>
<p><strong>Value:</strong> {{ Xref_cssresolution() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssbitmap() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>Indicates the resolution (pixel density) of the output device.  The resolution may be specified in either dots per inch (dpi) or dots per centimeter (dpcm).</p>
<h4>Example</h4>
<p>To apply a style sheet to devices with at least 300 dots per inch of resolution:</p>
<pre>@media print and (min-resolution: 300dpi) { ... }
</pre>
<h3>scan</h3>
<p><strong>Value:</strong> <code>progressive</code> | <code>interlace</code><br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_csstv() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>Describes the scanning process of television output devices.</p>
<div class="note"><strong>Note: </strong>Gecko (and therefore Firefox) does not currently support the <code>tv</code> media type, so this media feature is likewise unsupported.</div>
<h4>Example</h4>
<p>To apply a style sheet only to progressive scanning televisions:</p>
<pre>@media tv and (scan: progressive) { ... }
</pre>
<h3>width</h3>
<p><strong>Value:</strong> {{ Xref_csslength() }}<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}, {{ Xref_csstactile() }}<br>
<strong>Accepts min/max prefixes:</strong> yes</p>
<p>The <code>width</code> media feature describes the width of the rendering surface of the output device (such as the width of the document window, or the width of the page box on a printer).</p>
<div class="note"><strong>Note:</strong> As the user resizes the window, Firefox will switch style sheets as appropriate based on media queries using the <code>width</code> and <code>height</code> media features.</div>
<h4>Examples</h4>
<p>If you want to specify a style sheet for handheld devices, or screen devices with a width greater than 20em, you can use this style sheet:</p>
<pre>@media handheld and (min-width: 20em), screen and (min-width: 20em) { ... }
</pre>
<p>This media query specifies a style sheet that should apply to printed media wider than 8.5 inches:</p>
<pre>&lt;link rel="stylesheet" media="print and (min-width: 8.5in)"
    href="http://foo.com/mystyle.css" /&gt;
</pre>
<p>This query specifies a style sheet that is usable when the viewport is between 500 and 800 pixels wide:</p>
<pre>@media screen and (min-width: 500px) and (max-width: 800px) { ... }
</pre>
<h2>Mozilla-specific media features</h2>
<p>{{ gecko_minversion_header("1.9.2") }}</p>
<p>Mozilla offers several Gecko-specific media features. Some of these may be proposed as official media features.</p>
<h3>-moz-images-in-menus</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device allows images to appear in menus, this is 1; otherwise, the value is 0. This corresponds to the {{ cssxref(":-moz-system-metric(images-in-menus)") }} CSS pseudo class.</p>
<h3>-moz-mac-graphite-theme</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the user has configured their device to use the "Graphite" appearance on Mac OS X, this is 1. If the user is using the standard blue appearance, or is not on Mac OS X, this is 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(mac-graphite-theme)") }} CSS pseudo class.</p>
<h3>-moz-maemo-classic</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the user is using Maemo with the original theme, this is 1; if it's using the newer Fremantle theme, this is 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(windows-classic)") }} CSS pseudo class.</p>
<h3>-moz-scrollbar-end-backward</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device's user interface displays a backward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-end-backward)") }} CSS pseudo class.</p>
<h3>-moz-scrollbar-end-forward</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device's user interface displays a forward arrow button at the end of scrollbars, this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-end-backward)") }} CSS pseudo class.</p>
<h3>-moz-scrollbar-start-backward</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device's user interface displays a backward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-start-backward)") }} CSS pseudo class.</p>
<h3>-moz-scrollbar-start-forward</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device's user interface displays a forward arrow button at the beginning of scrollbars, this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-start-backward)") }} CSS pseudo class.</p>
<h3>-moz-scrollbar-thumb-proportional</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device's user interface displays the thumb of scrollbars proportionally (that is, sized based on the percentage of the document that is visible), this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(scrollbar-thumb-proportional)") }} CSS pseudo class.</p>
<h3>-moz-touch-enabled</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the device supports touch events (for a touch screen), this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(touch-enabled)") }} CSS pseudo class.</p>
<h4>Example</h4>
<p>You might use this to render your buttons slightly larger, for example, if the user is on a touch-screen device, to make them more finger-friendly.</p>
<h3>-moz-windows-classic</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the user is using Windows unthemed (in classic mode instead of using uxtheme), this is 1; otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(windows-classic)") }} CSS pseudo class.</p>
<h3>-moz-windows-compositor</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the user is using Windows with the DWM compositor, this is 1; otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(windows-compositor)") }} CSS pseudo class.</p>
<h3>-moz-windows-default-theme</h3>
<p><strong>Value:</strong> integer<br>
<span style="font-weight: bold;">Media</span><strong>:</strong> {{ Xref_cssvisual() }}<br>
<strong>Accepts min/max prefixes:</strong> no</p>
<p>If the user is currently using one of the default Windows themes (Luna, Royale, Zune, or Aero (including Vista Basic, Vista Advanced, and Aero Glass), this is 1. Otherwise it's 0.</p>
<p>This corresponds to the {{ cssxref(":-moz-system-metric(windows-default-theme)") }} CSS pseudo class.</p>
<h2>See also</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/css3-mediaqueries/" title="http://www.w3.org/TR/css3-mediaqueries/">CSS 3 media query specification</a></li> <li><a class="internal" href="/en/CSS/@media" title="En/CSS/@media">Media types</a></li>
</ul>
<p>{{ languages( { "fr": "fr/CSS/Media_queries" } ) }}</p>
Revert to this revision