FFFF csswg-drafts/mediaqueries/Overview.src.html at c1b7736eaae7fb59e560c0cdad06fa99b0f8c641 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
executable file
·
1361 lines (1038 loc) · 51 KB

File metadata and controls

executable file
·
1361 lines (1038 loc) · 51 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Queries Level 4</title>
<link rel=contents href="#contents">
<link rel=index href="#index">
<link rel="stylesheet" type="text/css" href="../default.css">
<link rel="stylesheet" type="text/css"
href="http://www.w3.org/StyleSheets/TR/W3C-[STATUS].css">
<style type="text/css">
/* delete this block when you've cleared out all the .replaceme elements */
.replaceme {
border: solid red;
padding: 0 0.5em;
margin: 0 0.1em;
background: yellow;
color: green;
}
.replaceme:before {
content: "FIXME(";
color: black;
}
.replaceme:after {
content: ")";
color: black;
}
blockquote {
background: #eef;
padding: 0.5em;
margin: 1em 0;
border: thin solid black; }
pre { font-family: courier, monospace; font-weight: bold; white-space: pre-wrap }
.example pre em { font-style: normal }
span.label { font-style: italic }
</style>
</head>
<div class="head">
<!--logo-->
<h1 id="media-queries">Media Queries Level 4</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:
<!-- <dd><a href="[VERSION]">http://www.w3.org/TR/[YEAR]/ED-mediaqueries4-[CDATE]/</a> -->
<dd><a href="http://dev.w3.org/csswg/mediaqueries4/">http://dev.w3.org/csswg/mediaqueries4/</a></dd>
<dt>Latest version:
<dd>N/A
<dt>Editor's draft:
<dd><a href="http://dev.w3.org/csswg/mediaqueries4/">http://dev.w3.org/csswg/mediaqueries4/</a>
<dt>Previous Version:</dt>
<dd>N/A
<dt>Issue Tracking:</dt>
<dd><a href="http://www.w3.org/Style/CSS/Tracker/products/7">http://www.w3.org/Style/CSS/Tracker/products/7</a>
<dt>Feedback:</dt>
<dd><a href="mailto:www-style@w3.org?subject=%5Bmediaqueries4%5D%20feedback">www-style@w3.org</a>
with subject line &ldquo;<kbd>[mediaqueries4] <var>&hellip; message topic &hellip;</var></kbd>&rdquo;
(<a rel="discussion" href="http://lists.w3.org/Archives/Public/www-style/">archives</a>)
<dt>Editors:
<dd class="vcard"><span class="given-name">Florian</span> <span class="family-name">Rivoal</span> &lt;<span class="email">florian&nbsp;@rivoal.net</span>&gt;
<dt>Previous Editors:
<dd class="vcard"><a class="url fn n" lang="no" href="http://people.opera.com/howcome/">
<span class="given-name">H&aring;kon</span> <span class="additional-name">Wium</span> <span class="family-name">Lie</span></a> &lt;<span class="email">howcome&nbsp;@opera.com</span>&gt;
<dd class="vcard"><a class="url fn" lang="tr" href="http://tantek.com/">Tantek &Ccedil;elik</a> &lt;<span class="email">tantek&nbsp;@cs.stanford.edu</span>&gt;
<dd class="vcard"><span class="given-name">Daniel</span> <span class="family-name">Glazman</span> &lt;<span class="email">daniel.glazman&nbsp;@disruptive-innovations.com</span>&gt;
<dd class="vcard"><a class="url fn n" lang="nl" href="http://annevankesteren.nl/" hreflang="en">Anne van Kesteren</a> &lt;<span class="email">annevk@opera.com</span>&gt;
</dl>
<!--copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p><em>Media Queries</em> allow authors to adapt the style applied to a
document based on the environment the document is being rendered in.
[[HTML401]] and [[!CSS21]] introduced this mechanism, by allowing detection of
the <em>media type</em>. For example, a document may use sans-serif fonts when
displayed on a screen and serif fonts when printed. ''screen'' and ''print''
are two media types that have been defined. Media Queries Level 3 [[MEDIAQ]]
refined this mechanism by allowing detection of individual characteristics, or
<em>media features</em>. For example, a document may use a different style when
displayed in ''portrait'' and in ''landscape'' mode, as detected by the
''orientation'' media feature.
<p>Media Queries Level 4 describes the mechanism, media types and media
features that already existed in [[MEDIAQ]], and further introduces new media
features.
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<h2 class="no-num no-toc" id="contents">
Table of contents</h2>
<!--toc-->
<h2 id="intro">
Introduction</h2>
<p><em>This section is not normative.</em>
<p>HTML4 [[HTML401]] and CSS2 [[!CSS21]] currently support media-dependent
style sheets tailored for different media types. For example, a
document may use different style sheets for screen and print. In
HTML4, this can be written as:</p>
<div class="example">
<pre><code>&lt;link rel="stylesheet" type="text/css" media="screen" href="sans-serif.css"&gt;
&lt;link rel="stylesheet" type="text/css" media="print" href="serif.css"&gt;<code></pre>
</div>
<p>Inside a CSS style sheet, one can declare that sections apply to
certain media types:</p>
<div class="example">
<pre><code>@media screen {
* { font-family: sans-serif }
}</code></pre>
</div>
<p>The ''print'' and ''screen'' media types are defined in HTML4. The
complete list of media types in HTML4 is: ''aural'', ''braille'',
''handheld'', ''print'', ''projection'', ''screen'', ''tty'', ''tv''. CSS2
defines the same list, deprecates ''aural'' and adds ''embossed'' and
''speech''. Also, ''all'' is used to indicate that the style sheet applies
to all media types.</p>
<p>Media-specific style sheets are supported by several user
agents. The most commonly used feature is to distinguish between
''screen'' and ''print''.</p>
<p>There have been requests for ways to describe in more detail
what type of output devices a style sheet applies to. Fortunately
HTML4 foresaw these requests and defined a forward-compatible
syntax for media types. Here is a quote from <a href=
"http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">HTML4,
section 6.13</a>:</p>
<blockquote cite="http://www.w3.org/TR/1999/REC-html401-19991224/types.html#h-6.13">
<p>Future versions of HTML may introduce new values and may allow
parameterized values. To facilitate the introduction of these
extensions, conforming user agents must be able to parse the <a href=
"http://www.w3.org/TR/1999/REC-html401-19991224/present/styles.html#adef-media"><samp>media</samp></a> attribute value as follows:</p>
<ol>
<li>The value is a comma-separated list of entries. For example,
<pre><code>media="screen, 3d-glasses, print and resolution &gt; 90dpi"</code></pre>
<p>is mapped to:</p>
<pre><code>"screen"
"3d-glasses"
"print and resolution > 90dpi"</code></pre>
</li>
<li>Each entry is truncated just before the first character that
isn't a US ASCII letter [a-zA-Z] (Unicode decimal 65-90, 97-122),
digit [0-9] (Unicode hex 30-39), or hyphen (45). In the example,
this gives:
<pre><code>"screen"
"3d-glasses"
"print"</code></pre>
</li>
</ol>
</blockquote>
<p>Media queries, as described in this specification, build on the
mechanism outlined in HTML4. The syntax of media queries fit into the
media type syntax reserved in HTML4. The <code class="html">media</code>
attribute of HTML4 also exists in XHTML and generic XML. The same
syntax can also be used inside in the ''@media'' and ''@import'' rules
of CSS.</p>
<p>However, the parsing rules for media queries are incompatible with those
of HTML4 so that they are consistent with those of media queries used in
CSS.</p>
<p class="note">HTML5 [[HTML5]] (at the moment of writing still work in
progress) references the Media Queries specification directly and thus
updates the rules for HTML.</p>
<h3 id="placement">
Module interactions</h3>
<p>This module replaces and extends the Media Queries, Media Type and Media Features
defined in [[!CSS21]] sections 7 and in [[!MEDIAQ]].
<h3 id="values">
Values</h3>
<p><em>This section is normative</em>
<p>Value types not defined in this specification, such as &lt;integer&gt;,
&lt;number&gt; or &lt;resolution&gt;, are defined in [[!CSS3VAL]]. Other CSS
modules may expand the definitions of these value types.</p>
<p>This specification also introduces one new value type.</p>
<p>The &lt;ratio&gt; value type is a positive (not zero or negative)
&lt;integer&gt; followed by optional whitespace, followed by a solidus ('/'),
followed by optional whitespace, followed by a positive &lt;integer&gt;.</p>
<h3 id="units">
Units</h3>
<p><em>This section is normative</em>
<p>The units used in media queries are the same as in other parts of CSS, as
defined in [[!CSS3VAL]]. For example, the pixel unit represents CSS pixels and
not physical pixels.</p>
<p>Relative units in media queries are based on the initial value, which means
that units are never based on results of declarations. For example, in HTML,
the ''em'' unit is relative to the initial value of 'font-size'.</p>
<h2 id="media0">Media Queries</h2>
<p>A media query consists of an optional media type and zero or more
<span class="index">expressions</span> that check for the conditions of
particular <span class="index">media features</span>.</p>
<p>Statements regarding media queries in this section assume the
<a href="#syntax">syntax section</a> is followed. Media queries that do not
conform to the syntax are discussed in the
<a href="#error-handling">error handling section</a>. I.e. the syntax takes
precedence over requirements in this section.</p>
<div class="example">
<p>Here is a simple example written in HTML:</p>
<pre><code>&lt;link rel="stylesheet" media="screen and (color)" href="example.css" /></code></pre>
<p>This example expresses that a certain style sheet
(<code>example.css</code>) applies to devices of a certain media type
(''screen'') with certain feature (it must be a color screen).</p>
</div>
<div class="example">
<p>Here the same media query written in an @import-rule in CSS:</p>
<pre><code>@import url(color.css) screen and (color);</code></pre>
</div>
<p>A media query is a logical expression that is either true or
false. A media query is true if the media type of the media query
matches the media type of the device where the user agent is running (as
defined in the "Applies to" line), and all expressions in the media query
are true.</p>
<p>A shorthand syntax is offered for media queries that apply to all
media types; the keyword ''all'' can be left out (along with the
trailing ''and''). I.e. if the media type is not explicitly given it is
''all''.</p>
<div class="example">
<p>I.e. these are identical:</p>
<pre><code>@media all and (min-width:500px) { &hellip; }
@media (min-width:500px) { &hellip; }</code></pre>
<p>As are these:</p>
<pre><code>@media (orientation: portrait) { &hellip; }
@media all and (orientation: portrait) { &hellip; }</code></pre>
</div>
<p>Several media queries can be combined in a media query list. A
comma-separated list of media queries. If one or more of the media queries
in the comma-separated list are true, the whole list is true, and otherwise
false. In the media queries syntax, the comma
expresses a logical OR, while the ''and'' keyword expresses a logical
AND.</p>
<div class="example">
<p>Here is an example of several media queries in a comma-separated
list using the an @media-rule in CSS:</p>
<pre><code>@media <em>screen and (color), projection and (color)</em> { &hellip; }</code></pre>
</div>
<p>If the media query list is empty (i.e. the declaration is the empty
string or consists solely of whitespace) it evaluates to true.</p>
<div class="example">
<p>I.e. these are equivalent:</p>
<pre><code>@media all { &hellip; }
@media { &hellip; }</code></pre>
</div>
<p>The logical NOT can be expressed through the ''not'' keyword. The
presence of the keyword ''not'' at the beginning of the media query negates
the result. I.e., if the media query had been true without the ''not''
keyword it will become false, and vice versa. User agents that only support
media types (as described in HTML4) will not recognize the ''not'' keyword
and the associated style sheet is therefore not applied.</p>
<div class="example">
<pre><code>&lt;link rel="stylesheet" media="<em>not screen and (color)</em>" href="example.css" /&gt;</code></pre>
</div>
<p>The keyword ''only'' can also be used to hide style sheets from
older user agents. User agents must process media queries starting
with ''only'' as if the ''only'' keyword was not present.</p>
<div class="example">
<pre><code>&lt;link rel="stylesheet" media="<em>only screen and (color)</em>" href="example.css" /&gt;</code></pre>
</div>
<p>The media queries syntax can be used with HTML, XHTML, XML [[XMLSTYLE]] and the @import and @media rules of CSS.</p>
<div class="example">
<p>Here is the same example written in HTML, XHTML, XML, @import and @media:</p>
<pre><code>&lt;link rel="stylesheet" media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css"></code></pre>
<pre><code>&lt;link rel="stylesheet" media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" /></code></pre>
<pre><code>&lt;?xml-stylesheet media="<em>screen and (color), projection and (color)</em>" rel="stylesheet" href="example.css" ?></code></pre>
<pre><code>@import url(example.css) <em>screen and (color), projection and (color)</em>;</code></pre>
<pre><code>@media <em>screen and (color), projection and (color)</em> { &hellip; }</code></pre>
<p class="note">The [[XMLSTYLE]] specification has not yet been updated to
use media queries in the <code>media</code> pseudo-attribute.</p>
</div>
<p>If a media feature does not apply to the device where the UA is
running, expressions involving the media feature will be false.</p>
<div class="example">
<p>The media feature ''device-aspect-ratio'' only applies to
visual devices. On an aural device, expressions involving
''device-aspect-ratio'' will therefore always be false:</p>
<pre><code>&lt;link rel="stylesheet" media="aural and (device-aspect-ratio: 16/9)" href="example.css" /&gt;</code></pre>
</div>
<p>Expressions will always be false if the unit of measurement does
not apply to the device. </p>
<div class="example">
<p>The ''px'' unit does not apply to ''speech'' devices so the following media query is always false:</p>
<pre><code>&lt;link rel="stylesheet" media="speech and (min-device-width: 800px)" href="example.css" /&gt;</code></pre>
<p>Note that the media queries in this example would have
been true if the keyword ''not'' had been added to the beginning of
the media query.</p>
</div>
<p>To avoid circular dependencies, it is never necessary to apply the
style sheet in order to evaluate expressions. For example, the aspect
ratio of a printed document may be influenced by a style sheet, but
expressions involving ''device-aspect-ratio'' will be based on the
default aspect ratio of the user agent.</p>
<p class=note>User agents are expected, but not required, to
re-evaluate and re-layout the page in response to changes in the user
environment, for example if the device is tilted from landscape to
portrait mode.
<h2>Syntax</h2>
<p>The media query syntax is described in terms of the
<a href="http://www.w3.org/TR/CSS21/grammar.html">CSS2 grammar</a>. As such,
rules not defined here are defined in CSS2. The
<code>media_query_list</code> production defined below replaces the
<code>media_list</code> production from CSS2. [[!CSS21]]</p>
<pre>media_query_list
: S* [media_query [ ',' S* media_query ]* ]?
;
media_query
: [ONLY S+ | NOT S+]? media_type [ S+ AND S+ expression ]* S*
| expression [ S+ AND S+ expression ]* S*
;
media_type
: IDENT
;
expression
: '(' S* media_feature S* [ ':' S* expr ]? ')'
;
media_feature
: IDENT
;</pre>
<p>COMMENT tokens, as defined by CSS2, do not occur in the grammar (to keep
it readable), but any number of these tokens may appear anywhere between
other tokens. [[!CSS21]]</p>
<p>The following new definitions are introduced:</p>
<pre>L l|\\0{0,4}(4c|6c)(\r\n|[ \t\r\n\f])?|\\l
Y y|\\0{0,4}(59|79)(\r\n|[ \t\r\n\f])?|\\y</pre>
<p>The following new tokens are introduced:</p>
<pre>{O}{N}{L}{Y} {return ONLY;}
{N}{O}{T} {return NOT;}
{A}{N}{D} {return AND;}
{num}{D}{P}{I} {return RESOLUTION;}
{num}{D}{P}{C}{M} {return RESOLUTION;}</pre>
<p><code>RESOLUTION</code> is to be added to the CSS2
<code>term</code> production.</p>
<p>CSS style sheets are generally case-insensitive, and this is
also the case for media queries.</p>
<p>In addition to conforming to the syntax, each media query needs to use
media types and media features according to their respective specification
in order to be considered conforming.</p>
<div class="example">
<p>Only the first media query is conforming in the example below because the
"example" media type does not exist.</p>
<pre><code>@media all { body { background:lime } }
@media example { body { background:red } }</code></pre>
</div>
<h3>Error Handling</h3>
<p>For media queries that are not conforming user agents need to follow the
rules described in this section.</p>
<ul>
<li>
<p><strong>Unknown media types.</strong> Unknown media types evaluate to
false. Effectively, they are treated identically to known media types
that do not match the media type of the device. However, an exception is made
for media types ''not'', ''and'', ''only'' and ''or''. Even though they do
match the IDENT production, they must not be treated as unknown media types,
but rather trigger the malformed query clause.</p>
<div class="example">
<p>The media query "<code>unknown</code>" will evaluate to false, unless
<code>unknown</code> is actually a supported media type. Similarly,
"<code>not unknown</code>" will evaluate to true.</p>
</div>
<p class="note">Unknown media types are distinct from media types that do
not actually match the IDENT production. Those fall under the malformed
media query clause.</p>
<li>
<p><strong>Unknown media features.</strong> User agents are to represent a
media query as "<code>not all</code>" when one of the specified media
features is not known.</p>
<div class="example">
<pre><code>&lt;link rel="stylesheet" media="screen and (max-weight: 3kg) and (color), (color)" href="example.css" /&gt;</code></pre>
<p>In this example, the first media query will be represented as
"<code>not all</code>" and evaluate to false and the second media query
is evaluated as if the first had not been specified, effectively.</p>
</div>
<div class="example">
<pre><code>@media (min-orientation:portrait) { &hellip; }</code></pre>
<p>Is represented as "<code>not all</code>" because the ''orientation''
feature does not accept the ''min-'' prefix.</p>
</div>
<li>
<p><strong>Unknown media feature values.</strong> As with unknown media
features, user agents are to represent a media query as
"<code>not all</code>" when one of the specified media feature values is
not known.</p>
<div class="example">
<p>The media query <code>(color:20example)</code> specifies an unknown
value for the ''color'' media feature and is therefore represented as
"<code>not all</code>".</p>
</div>
<div class="example">
<p>This media query is represented as "<code>not all</code>" because
negative lengths are not allowed for the ''width'' media feature:</p>
<pre><code>@media (min-width: -100px) { &hellip; }</code></pre>
</div>
<li>
<p><strong>Malformed media query.</strong> User agents are to handle
unexpected tokens encountered while parsing a media query by reading until
the end of the media query, while observing
<a href="http://www.w3.org/TR/CSS21/syndata.html#block">the rules for
matching pairs</a> of (), [], {}, "", and &#39;&#39;, and correctly handling
escapes. Media queries with unexpected tokens are represented as
"<code>not all</code>". [[!CSS21]]
<div class="example">
<pre><code>@media (example, all,), speech { /* only applicable to speech devices */ }
@media &amp;test, screen { /* only applicable to screen devices */ }</code></pre>
</div>
<div class="example">
<p>The following is an malformed media query because having no space
between ''and'' and the expression is not allowed. (That is reserved for
the functional notation syntax.)</p>
<pre><code>@media all and(color) { &hellip; }</code></pre>
</div>
<div class="example">
<p>The following is a malformed media query because it uses ''only'' and 'or' as media types.</p>
<pre><code>@media only and or { &hellip; }</code></pre>
</div>
<p>Media queries are expected to follow the error handling rules of the
host language as well.</p>
<div class="example">
<pre><code>@media test;,all { body { background:lime } }</code></pre>
<p>&hellip; will not apply because the semicolon terminates the
<code>@media</code> rule in CSS.</p>
</div>
</ul>
<h2 id="media1">Media features</h2>
<p>Syntactically, media features resemble CSS properties: they have
names and accept certain values. There are, however, several
important differences between properties and media features:</p>
<ul>
<li>Properties are used in <em>declarations</em> to give
information about how to present a document. Media features are
used in <em>expressions</em> to describe requirements of the output
device.</li>
<li>Most media features accept optional ''min-'' or ''max-'' prefixes
to express "greater or equal to" and "smaller or equal to"
constraints. This syntax is used to avoid "&lt;" and "&gt;"
characters which may conflict with HTML and XML. Those media features
that accept prefixes will most often be used with prefixes, but can
also be used alone.</li>
<li>Properties always require a value to form a declaration. Media
features, on the other hand, can also be used without a value. For a media
feature <var>feature</var>, <code>(<var>feature</var>)</code> will evaluate
to true if <code>(<var>feature</var>:<var>x</var>)</code> will evaluate to
true for a value <var>x</var> other than zero or zero followed by a unit
identifier (i.e., other than <code>0</code>, <code>0px</code>,
<code>0em</code>, etc.) or the keyword 'none'. Media features that are prefixed by min/max cannot
be used without a value. When a media feature prefixed with min/max is used
without a value it makes the media query malformed.</li>
<li>Properties may accept more complex values, e.g., calculations that
involve several other values. Media features only accept single
values: one keyword, one number, or a number with a unit identifier.
(The only exceptions are the ''aspect-ratio'' and ''device-aspect-ratio''
media features.)
</li>
</ul>
<div class="example">
<p>For example, the ''color'' media feature can form expressions without a
value (''(color)''), or with a value (''(min-color: 1)'').</p>
</div>
<p class="note">This specification defines media features usable with visual and
tactile devices. Similarly, media features can be defined for aural
media types.</p>
<h3 id="width">width</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;length&gt;<br>
<span class="label">Applies to:</span> visual and tactile media
types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''width'' media feature describes the width of the targeted display
area of the output device. For continuous media, this is the width
of the viewport (as described by CSS2, section 9.1.1 [[!CSS21]]) including
the size of a rendered scroll bar (if any). For paged media, this is the
width of the page box (as described by CSS2, section 13.2 [[!CSS21]]).</p>
<p>A specified &lt;length> cannot be negative.</p>
<div class="example">
<p>For example, this media query expresses that the style sheet is
usable on printed output wider than 25cm:</p>
<pre><code>&lt;link rel="stylesheet" media="print and (min-width: 25cm)" href="http://&hellip;" /></code></pre>
</div>
<div class="example">
<p>This media query expresses that the style sheet is usable on
devices with viewport (the part of the screen/paper where the
document is rendered) widths between 400 and 700 pixels:</p>
<pre><code>@media screen and (min-width: 400px) and (max-width: 700px) { &hellip; }</code></pre>
</div>
<div class="example">
<p>This media query expresses that style sheet is usable on screen
and handheld devices if the width of the viewport is greater than
20em.</p>
<pre><code>@media handheld and (min-width: 20em),
screen and (min-width: 20em) { &hellip; }</code></pre>
<p>The ''em'' value is relative to the initial value of
‘font-size’.</p>
</div>
<h3 id="height">height</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;length&gt;<br>
<span class="label">Applies to:</span> visual and tactile media
types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''height'' media feature describes the height of the targeted display
area of the output device. For continuous media, this is the height
of the viewport including the size of a rendered scroll bar (if any). For
paged media, this is the height of the page box.</p>
<p>A specified &lt;length> cannot be negative.</p>
<h3 id="device-width">device-width</h3>
<div class="media-feature"><span class="label">Value:</span> &lt;length&gt;<br>
<span class="label">Applies to:</span> visual and tactile media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''device-width'' media feature describes the width of the rendering
surface of the output device. For continuous media, this is the width
of the screen. For paged media, this is the width of the page sheet
size.</p>
<p>A specified &lt;length> cannot be negative.</p>
<div class="example">
<pre><code>@media screen and (device-width: 800px) { &hellip; }</code></pre>
<p>In the example above, the style sheet will apply only to screens
that currently displays exactly 800 horizontal pixels. The ''px'' unit is
of the logical kind, as described in the <a href="#units">Units</a>
section.</p>
</div>
<h3 id="device-height">device-height</h3>
<div class="media-feature"><span class="label">Value:</span> &lt;length&gt;<br>
<span class="label">Applies to:</span> visual and tactile media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''device-height'' media feature describes the height of the rendering
surface of the output device. For continuous media, this is the height
of the screen. For paged media, this is the height of the page sheet
size.</p>
<p>A specified &lt;length> cannot be negative.</p>
<div class="example">
<pre><code>&lt;link rel="stylesheet" media="screen and (device-height: 600px)" /&gt;</code></pre>
<p>In the example above, the style sheet will apply only to screens
that have exactly 600 vertical pixels. Note that the definition of the
''px'' unit is the same as in other parts of CSS.</p>
</div>
<h3>orientation</h3>
<div class="media-feature"><span class="label">Value:</span>
portrait | landscape<br>
<span class="label">Applies to:</span> bitmap media types<br>
<span class="label">Accepts min/max prefixes:</span> no<br>
</div>
<p>The ''orientation'' media feature is ''portrait'' when the value of the
''height'' media feature is greater than or equal to the value of the
''width'' media feature. Otherwise ''orientation'' is ''landscape''.</p>
<div class="example">
<pre><code>@media all and (orientation:portrait) { &hellip; }
@media all and (orientation:landscape) { &hellip; }</code></pre>
</div>
<h3>aspect-ratio</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;ratio&gt;<br>
<span class="label">Applies to:</span> bitmap media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''aspect-ratio'' media feature is defined as the ratio of the value
of the ''width'' media feature to the value of the ''height'' media
feature.</p>
<h3>device-aspect-ratio</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;ratio&gt;<br>
<span class="label">Applies to:</span> bitmap media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''device-aspect-ratio'' media feature is defined as the ratio of the
value of the ''device-width'' media feature to the value of the
''device-height'' media feature.</p>
<div class="example">
<p>For example, if a screen device with square pixels has 1280 horizontal
pixels and 720 vertical pixels (commonly referred to as "16:9"), the
following Media Queries will all match the device:</p>
<pre><code>@media screen and (device-aspect-ratio: 16/9) { &hellip; }
@media screen and (device-aspect-ratio: 32/18) { &hellip; }
@media screen and (device-aspect-ratio: 1280/720) { &hellip; }
@media screen and (device-aspect-ratio: 2560/1440) { &hellip; }</code></pre>
</div>
<h3 id="color">color</h3>
<div class="media-feature"><span class="label">Value:</span> &lt;integer&gt;<br>
<span class="label">Applies to:</span> visual media types<br>
<span class="label">Accept min/max prefixes:</span> yes<br>
</div>
<p>The ''color'' media feature describes the number of bits per color
component of the output device. If the device is not a color device,
the value is zero.</p>
<p>A specified &lt;integer> cannot be negative.</p>
<div class="example">
<p>For example, these two media queries express that a style sheet
applies to all color devices:</p>
<pre><code>@media all and (color) { &hellip; }
@media all and (min-color: 1) { &hellip; }</code></pre>
</div>
<div class="example">
<p>This media query expresses that a style sheet applies to color
devices with 2 or more bits per color component:</p>
<pre><code>@media all and (min-color: 2) { &hellip; }</code></pre>
</div>
<p>If different color components are represented by
different number of bits, the smallest number is used.</p>
<div class="example">
<p>For instance, if an 8-bit color system represents the red
component with 3 bits, the green component with 3 bits and the blue
component with 2 bits, the ''color'' media feature will have a value
of 2.</p>
</div>
<p>In a device with indexed colors, the minimum number of bits per
color component in the lookup table is used.</p>
<p class="note">The described functionality is only able to describe color
capabilities at a superficial level. If further functionality is
required, RFC2531 [[RFC2531]] provides more specific media features
which may be supported at a later stage.</p>
<h3 id="color-index">color-index</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;integer&gt;<br>
<span class="label">Applies to:</span> visual media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''color-index'' media feature describes the number of entries
in the color lookup table of the output device. If the device does not
use a color lookup table, the value is zero.
<p>A specified &lt;integer> cannot be negative.</p>
<div class="example">
<p>For example, here are two ways to express that a style sheet
applies to all color index devices:</p>
<pre><code>@media all and (color-index) { &hellip; }
@media all and (min-color-index: 1) { &hellip; }</code></pre>
</div>
<div class="example">
<p>This media query expresses that a style sheet applies to a color
index device with 256 or more entries:</p>
<pre><code>&lt;?xml-stylesheet media="all and (min-color-index: 256)"
href="http://www.example.com/&hellip;" ?&gt;</code></pre>
</div>
<h3 id="monochrome">monochrome</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;integer&gt;<br>
<span class="label">Applies to:</span> visual media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''monochrome'' media feature describes the number of bits per
pixel in a monochrome frame buffer. If the device is not a
monochrome device, the output device value will be 0.</p>
<p>A specified &lt;integer> cannot be negative.</p>
<div class="example">
<p>For example, here are two ways to express that a style sheet
applies to all monochrome devices:</p>
<pre><code>@media all and (monochrome) { &hellip; }
@media all and (min-monochrome: 1) { &hellip; }</code></pre>
</div>
<div class="example">
<p>Express that a style sheet applies to monochrome
devices with more than 2 bits per pixels:</p>
<pre><code>@media all and (min-monochrome: 2) { &hellip; }</code></pre>
</div>
<div class="example">
<p>Express that there is one style sheet for color pages and another for monochrome:</p>
<pre><code>&lt;link rel="stylesheet" media="print and (color)" href="http://&hellip;" /&gt;
&lt;link rel="stylesheet" media="print and (monochrome)" href="http://&hellip;" /&gt;</code></pre>
</div>
<h3 id="resolution">resolution</h3>
<div class="media-feature"><span class="label">Value:</span>
&lt;resolution&gt;<br>
<span class="label">Applies to:</span> bitmap media types<br>
<span class="label">Accepts min/max prefixes:</span> yes<br>
</div>
<p>The ''resolution'' media feature describes the resolution of the
output device, i.e. the density of the pixels. When querying devices
with non-square pixels, in ''min-resolution'' queries the least-dense
dimension must be compared to the specified value and in
''max-resolution'' queries the most-dense dimensions must be compared
instead. A ''resolution'' (without a "min-" or "max-" prefix) query
never matches a device with non-square pixels.</p>
<p>For printers, this corresponds to the screening resolution (the
resolution for printing dots of arbitrary color).</p>
<div class="issue">Another media feature should probably be added to deal with the type of resolution authors want to know to deal with monochrome printing.</div>
<div class="example">
<p>For example, this media query expresses that a style sheet is
usable on devices with resolution greater than 300 dots per
CSS ''inch'':</p>
<pre><code>@media print and (min-resolution: 300dpi) { &hellip; }</code></pre>
</div>
<div class="example">
<p>This media query expresses that a style sheet is
usable on devices with resolution greater than 118 dots per
CSS ''centimeter'':</p>
<pre><code>@media print and (min-resolution: 118dpcm) { &hellip; }</code></pre>
</div>
<h3 id="scan">scan</h3>
<div class="media-feature"><span class="label">Value:</span>
progressive | interlace<br>
<span class="label">Applies to:</span> "tv" media types<br>
<span class="label">Accepts min/max prefixes:</span> no<br>
</div>
<p>The ''scan'' media feature describes the scanning process of "tv"
output devices.</p>
<div class="example">
<p>For example, this media query expresses that a style sheet is
usable on tv devices with progressive scanning:</p>
<pre><code>@media tv and (scan: progressive) { &hellip; }</code></pre>
</div>
<h3 id="grid">grid</h3>
<div class="media-feature"><span class="label">Value:</span> &lt;integer&gt;<br>
<span class="label">Applies to:</span> visual and tactile media types<br>
<span class="label">Accepts min/max prefixes:</span> no<br>
</div>
<p>The ''grid'' media feature is used to query whether the output device
is grid or bitmap. If the output device is grid-based (e.g., a "tty"
terminal, or a phone display with only one fixed font), the value will
be 1. Otherwise, the value will be 0.</p>
<p>Only 0 and 1 are valid values. (This includes -0.) Thus everything else
creates a malformed media query.</p>
<div class="example">
<p>Here are two examples:</p>
<pre><code>@media handheld and (grid) and (max-width: 15em) { &hellip; }</code>
<code>@media handheld and (grid) and (device-max-height: 7em) { &hellip; }</code></pre>
</div>
<h3 id="script">script</h3>
<div class="media-feature"><span class="label">Value:</span> &lt;integer&gt;<br>
<span class="label">Applies to:</span>all media types<br>
<span class="label">Accepts min/maxprefixes:</span> no<br
</div>
<p>The 'script' media feature is used to query whether ECMAscript is supported
on the current document. If the user agent supports ECMAscript, and that
support is active for the current document the value must be 1. Otherwise, the
value must be 0.</p>
<p>Some user agents have the ability to turn off ECMAscript support on a per
script basis or per domain basis, allowing some, but not all, scripts to run in
a particular document. The ''script'' media feature does not allow fine grained
detection of which script is allowed to run. In this scenario, the value of the
'script' media feature should be 1 if scripts originating on the same domain as
the document are allowed to run, and 0 otherwise.</p>
<p class="note">A future level of CSS may extend this media feature to allow
fine-grained detection of which script is allowed to run.</p>
<p>Only 0 and 1 are valid values. (This includes -0.) Thus everything else
creates a malformed media query.</p>
<h3 id="pointer">pointer</h3>
<div class="media-feature"><span class="label">Value:</span> none | coarse | fine<br>
<span class="label">Applies to:</span> visual and tactile media types<br>
<span class="label">Accepts min/max prefixes:</span> no<br>
</div>
<p>The ''pointer'' media feature is used to query about the presence and
accuracy of a pointing device such as a mouse. If a device has multiple input
mechanisms, it is recommended that the UA reports the characteristics of the
least capable pointing device of the primary input mechanisms. This