8000 csswg-drafts/mediaqueries/Overview.html at b994681d89165a061a0b193aa11192644e3a8d40 · w3c/csswg-drafts · GitHub
Skip to content

Latest commit

 

History

History
4417 lines (3142 loc) · 205 KB

File metadata and controls

4417 lines (3142 loc) · 205 KB
<!doctype html>
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Media Queries Level 4</title>
<link href="../default.css" rel="stylesheet" type="text/css">
<link href="../csslogo.ico" rel="shortcut icon" type="image/x-icon">
<style>
body {
background: url("https://www.w3.org/StyleSheets/TR/logo-ED") top left no-repeat white;
background-attachment: fixed;
color: black;
font-family: sans-serif;
margin: 0 auto;
max-width: 50em;
padding: 2em 1em 2em 70px;
}
:link { color: #00C; background: transparent }
:visited { color: #609; background: transparent }
a[href]:active { color: #C00; background: transparent }
a[href]:hover { background: #ffa }
a[href] img { border-style: none }
h1, h2, h3, h4, h5, h6 { text-align: left }
h1, h2, h3 { color: #005A9C; }
h1 { font: 170% sans-serif }
h2 { font: 140% sans-serif }
h3 { font: 120% sans-serif }
h4 { font: bold 100% sans-serif }
h5 { font: italic 100% sans-serif }
h6 { font: small-caps 100% sans-serif }
.hide { display: none }
div.head { margin-bottom: 1em }
div.head h1 { margin-top: 2em; clear: both }
div.head table { margin-left: 2em; margin-top: 2em }
p.copyright { font-size: small }
p.copyright small { font-size: small }
pre { margin-left: 2em }
dt { font-weight: bold }
ul.toc, ol.toc {
list-style: none;
}
</style>
<meta content="Bikeshed 1.0.0" name="generator">
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style>
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style>
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style>
<style>svg.railroad-diagram{background-color:hsl(30,20%,95%);}svg.railroad-diagram path{stroke-width:3;stroke:black;fill:rgba(0,0,0,0);}svg.railroad-diagram text{font:bold 14px monospace;text-anchor:middle;}svg.railroad-diagram text.label{text-anchor:start;}svg.railroad-diagram text.comment{font:italic 12px monospace;}svg.railroad-diagram rect{stroke-width:3;stroke:black;fill:hsl(120,100%,90%);}</style>
<style>
#pointer-hover-table { margin: 1em auto; text-align: center; border-collapse: collapse; max-width: 40em; }
#pointer-hover-table td, #pointer-hover-table th { padding: .5em; }
#pointer-hover-table thead tr+tr th { border-bottom: 1px solid silver; }
#pointer-hover-table tbody td:first-of-type { border-left: 1px solid silver; }
</style>
</head>
<body class="h-entry">
<div class="head">
<p data-fill-with="logo"><a class="logo" href="http://www.w3.org/">
<img alt="W3C" height="48" src="https://www.w3.org/Icons/w3c_home" width="72">
</a>
</p>
<h1 class="p-name no-ref" id="title">Media Queries Level 4</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft,
<time class="dt-updated" datetime="2015-05-15">15 May 2015</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
<dd><a class="u-url" href="http://dev.w3.org/csswg/mediaqueries4/">http://dev.w3.org/csswg/mediaqueries4/</a>
<dt>Latest version:
<dd><a href="http://www.w3.org/TR/mediaqueries-4/">http://www.w3.org/TR/mediaqueries-4/</a>
<dt>Feedback:
<dd><span><a href="mailto:www-style@w3.org?subject=%5Bmediaqueries%5D%20feedback">www-style@w3.org</a> with subject line “<kbd>[mediaqueries] <var>… message topic …</var></kbd>” (<a href="http://lists.w3.org/Archives/Public/www-style/" rel="discussion">archives</a>)</span>
<dt>Issue Tracking:
<dd><a href="#issues-index">Inline In Spec</a>
<dt class="editor">Editors:
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="http://florian.rivoal.net">Florian Rivoal</a> (<span class="p-org org">Invited Expert</span>) <a class="u-email email" href="mailto:florian@rivoal.net">florian@rivoal.net</a>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-url url" href="http://xanthir.com/contact/">Tab Atkins Jr.</a> (<span class="p-org org">Google</span>)
<dt>Former Editors:
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:howcome@opera.com">Håkon Wium Lie</a> (<span class="p-org org">Opera</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:tantek@cs.standard.edu">Tantek Çelik</a> (<span class="p-org org">Mozilla</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:daniel@glazman.org">Daniel Glazman</a> (<span class="p-org org">Disruptive Innovations</span>)
<dd>
<dd class="editor p-author h-card vcard"><a class="p-name fn u-email email" href="mailto:annevk@annevk.nl">Anne van Kesteren</a> (<span class="p-org org">Mozilla</span>)
</dl>
</div>
<div data-fill-with="warning"></div>
<p class="copyright" data-fill-with="copyright"><a href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a> © 2015 <a href="http://www.w3.org/"><abbr title="World Wide Web Consortium">W3C</abbr></a><sup>®</sup> (<a href="http://www.csail.mit.edu/"><abbr title="Massachusetts Institute of Technology">MIT</abbr></a>, <a href="http://www.ercim.eu/"><abbr title="European Research Consortium for Informatics and Mathematics">ERCIM</abbr></a>, <a href="http://www.keio.ac.jp/">Keio</a>, <a href="http://ev.buaa.edu.cn/">Beihang</a>). W3C <a href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>, <a href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a> and <a href="http://www.w3.org/Consortium/Legal/copyright-documents">document use</a> rules apply.
</p>
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
<div class="p-summary" data-fill-with="abstract">
<p><a data-link-type="dfn" href="#media-query">Media Queries</a> allow authors to test and query values or features of the user agent or display device, independent of the document being rendered. They are used in the CSS @media rule to conditionally apply styles to a document, and in various other contexts and languages, such as HTML and Javascript.</p>
<p>Media Queries Level 4 describes the mechanism and syntax of media queries, media types, and media features. It extends and supersedes the features defined in Media Queries Level 3.</p>
<a href="http://www.w3.org/TR/CSS/">CSS</a> is a language for describing the rendering of structured documents
(such as HTML and XML)
on screen, on paper, in speech, etc.</div>
<h2 class="no-num no-toc no-ref heading settled" id="status"><span class="content">Status of this document</span></h2>
<div data-fill-with="status">
<p>
This is a public copy of the editors’ draft.
It is provided for discussion only and may change at any moment.
Its publication here does not imply endorsement of its contents by W3C.
Don’t cite this document other than as work in progress.
</p>
<p>
The (<a href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public mailing list
<a href="mailto:www-style@w3.org?Subject=%5Bmediaqueries%5D%20PUT%20SUBJECT%20HERE">www-style@w3.org</a>
(see <a href="http://www.w3.org/Mail/Request">instructions</a>)
is preferred for discussion of this specification.
When sending e-mail,
please put the text “mediaqueries” in the subject,
preferably like this:
“[mediaqueries] <em>…summary of comment…</em>”
</p>
<p>
This document was produced by the <a href="http://www.w3.org/Style/CSS/members">CSS Working Group</a>
(part of the <a href="http://www.w3.org/Style/">Style Activity</a>).
</p>
<p>
This document was produced by a group operating under
the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent Policy</a>.
W3C maintains a <a href="http://www.w3.org/2004/01/pp-impl/32061/status" rel="disclosure">public list of any patent disclosures</a>
made in connection with the deliverables of the group;
that page also includes instructions for disclosing a patent.
An individual who has actual knowledge of a patent which the individual believes contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential Claim(s)</a>
must disclose the information in accordance with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the W3C Patent Policy</a>.
</p>
<p>
This document is governed by the <a href="http://www.w3.org/2014/Process-20140801/" id="w3c_process_revision">1 August 2014 W3C Process Document</a>.
</p>
<p>
</p></div>
<div data-fill-with="at-risk"></div>
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
<div data-fill-with="table-of-contents" role="navigation">
<ul class="toc" role="directory">
<li><a href="#intro"><span class="secno">1</span> <span class="content">
Introduction</span></a>
<ul class="toc">
<li><a href="#placement"><span class="secno">1.1</span> <span class="content">
Module interactions</span></a>
<li><a href="#values"><span class="secno">1.2</span> <span class="content">
Values</span></a>
<li><a href="#units"><span class="secno">1.3</span> <span class="content">
Units</span></a>
</ul>
<li><a href="#media"><span class="secno">2</span> <span class="content">
Media Queries</span></a>
<ul class="toc">
<li><a href="#mq-list"><span class="secno">2.1</span> <span class="content">
Combining Media Queries</span></a>
<li><a href="#mq-prefix"><span class="secno">2.2</span> <span class="content">
Media Query Modifiers</span></a>
<ul class="toc">
<li><a href="#mq-not"><span class="secno">2.2.1</span> <span class="content">
Negating a Media Query: the <span class="css">not</span> keyword</span></a>
<li><a href="#mq-only"><span class="secno">2.2.2</span> <span class="content">
Hiding a Media Query From Legacy User Agents: the <span class="css">only</span> keyword</span></a>
</ul>
<li><a href="#media-types"><span class="secno">2.3</span> <span class="content">
Media Types</span></a>
<li><a href="#mq-features"><span class="secno">2.4</span> <span class="content">
Media Features</span></a>
<ul class="toc">
<li><a href="#mq-ranges"><span class="secno">2.4.1</span> <span class="content">
Media Feature Types: “range” and “discrete”</span></a>
<li><a href="#mq-boolean-context"><span class="secno">2.4.2</span> <span class="content">
Evaluating Media Features in a Boolean Context</span></a>
<li><a href="#mq-range-context"><span class="secno">2.4.3</span> <span class="content">
Evaluating Media Features in a Range Context</span></a>
<li><a href="#mq-min-max"><span class="secno">2.4.4</span> <span class="content">
Using “min-” and “max-” Prefixes On Range Features</span></a>
</ul>
<li><a href="#media-conditions"><span class="secno">2.5</span> <span class="content">Combining Media Features</span></a>
</ul>
<li><a href="#mq-syntax"><span class="secno">3</span> <span class="content">
Syntax</span></a>
<ul class="toc">
<li><a href="#error-handling"><span class="secno">3.1</span> <span class="content">
Error Handling</span></a>
</ul>
<li><a href="#mf-dimensions"><span class="secno">4</span> <span class="content">
Screen/Device Dimensions Media Features</span></a>
<ul class="toc">
<li><a href="#width"><span class="secno">4.1</span> <span class="content">
width</span></a>
<li><a href="#height"><span class="secno">4.2</span> <span class="content">
height</span></a>
<li><a href="#aspect-ratio"><span class="secno">4.3</span> <span class="content">
aspect-ratio</span></a>
<li><a href="#orientation"><span class="secno">4.4</span> <span class="content">
orientation</span></a>
</ul>
<li><a href="#mf-display-quality"><span class="secno">5</span> <span class="content">
Display Quality Media Features</span></a>
<ul class="toc">
<li><a href="#resolution"><span class="secno">5.1</span> <span class="content">
resolution</span></a>
<li><a href="#scan"><span class="secno">5.2</span> <span class="content">
scan</span></a>
<li><a href="#grid"><span class="secno">5.3</span> <span class="content">
grid</span></a>
<li><a href="#update-frequency"><span class="secno">5.4</span> <span class="content">
update-frequency</span></a>
<li><a href="#mf-overflow-block"><span class="secno">5.5</span> <span class="content">
overflow-block</span></a>
<li><a href="#mf-overflow-inline"><span class="secno">5.6</span> <span class="content">
overflow-inline</span></a>
</ul>
<li><a href="#mf-colors"><span class="secno">6</span> <span class="content">
Color Media Features</span></a>
<ul class="toc">
<li><a href="#color"><span class="secno">6.1</span> <span class="content">
color</span></a>
<li><a href="#color-index"><span class="secno">6.2</span> <span class="content">
color-index</span></a>
<li><a href="#monochrome"><span class="secno">6.3</span> <span class="content">
monochrome</span></a>
<li><a href="#inverted"><span class="secno">6.4</span> <span class="content">
inverted-colors</span></a>
</ul>
<li><a href="#mf-interaction"><span class="secno">7</span> <span class="content">
Interaction Media Features</span></a>
<ul class="toc">
<li><a href="#pointer"><span class="secno">7.1</span> <span class="content">
pointer</span></a>
<li><a href="#hover"><span class="secno">7.2</span> <span class="content">
hover</span></a>
<li><a href="#any-input"><span class="secno">7.3</span> <span class="content">
any-pointer and any-hover</span></a>
</ul>
<li><a href="#mf-environment"><span class="secno">8</span> <span class="content">
Environment Media Features</span></a>
<ul class="toc">
<li><a href="#light-level"><span class="secno">8.1</span> <span class="content">
light-level</span></a>
</ul>
<li><a href="#mf-scripting"><span class="secno">9</span> <span class="content">
Scripting Media Features</span></a>
<ul class="toc">
<li><a href="#scripting"><span class="secno">9.1</span> <span class="content">
scripting</span></a>
</ul>
<li><a href="#custom-mq"><span class="secno">10</span> <span class="content">
Custom Media Queries</span></a>
<ul class="toc">
<li><a href="#script-custom-mq"><span class="secno">10.1</span> <span class="content">
Script-based Custom Media Queries</span></a>
<li><a href="#custom-mq-cssom"><span class="secno">10.2</span> <span class="content">
CSSOM</span></a>
</ul>
<li><a href="#mf-deprecated"><span class="secno">11</span> <span class="content">
Appendix A: Deprecated Media Features</span></a>
<li><a href="#changes"><span class="secno"></span> <span class="content">
Changes</span></a>
<ul class="toc">
<li><a href="#changes-2012"><span class="secno"></span> <span class="content">
Changes Since the Media Queries Level 3</span></a>
</ul>
<li><a href="#acknowledgments"><span class="secno"></span> <span class="content">
Acknowledgments</span></a>
<li><a href="#conformance"><span class="secno"></span> <span class="content">
Conformance</span></a>
<ul class="toc">
<li><a href="#conventions"><span class="secno"></span> <span class="content">
Document conventions</span></a>
<li><a href="#conformance-classes"><span class="secno"></span> <span class="content">
Conformance classes</span></a>
<li><a href="#partial"><span class="secno"></span> <span class="content">
Partial implementations</span></a>
<li><a href="#experimental"><span class="secno"></span> <span class="content">
Experimental implementations</span></a>
<li><a href="#testing"><span class="secno"></span> <span class="content">
Non-experimental implementations</span></a>
</ul>
<li><a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
<ul class="toc">
<li><a href="#index-defined-here"><span class="secno"></span> <span class="content">Terms defined by this specification</span></a>
<li><a href="#index-defined-elsewhere"><span class="secno"></span> <span class="content">Terms defined by reference</span></a>
</ul>
<li><a href="#references"><span class="secno"></span> <span class="content">References</span></a>
<ul class="toc">
<li><a href="#normative"><span class="secno"></span> <span class="content">Normative References</span></a>
<li><a href="#informative"><span class="secno"></span> <span class="content">Informative References</span></a>
</ul>
<li><a href="#property-index"><span class="secno"></span> <span class="content">Property Index</span></a>
<ul class="toc">
<li><a href="#media-descriptor-table"><span class="secno"></span> <span class="content"><span>@media</span> Descriptors</span></a>
</ul>
<li><a href="#idl-index"><span class="secno"></span> <span class="content">IDL Index</span></a>
<li><a href="#issues-index"><span class="secno"></span> <span class="content">Issues Index</span></a>
</ul></div>
<main>
<h2 class="heading settled" data-level="1" id="intro"><span class="secno">1. </span><span class="content">
Introduction</span><a class="self-link" href="#intro"></a></h2>
<p><em>This section is not normative.</em></p>
<p>HTML4 <a data-link-type="biblio" href="#biblio-html401">[HTML401]</a> defined a mechanism to support media-dependent style sheets,
tailored for different <a data-link-type="dfn" href="#media-type">media types</a>.
For example, a document may use different style sheets for screen and for print.
In HTML, this can be written as:</p>
<div class="example" id="example-b983fdd2"><a class="self-link" href="#example-b983fdd2"></a>
<pre>&lt;link rel="stylesheet" type="text/css" media="screen" href="style.css">
&lt;link rel="stylesheet" type="text/css" media="print" href="print.css">
</pre>
</div>
<p>CSS adapted and extended this functionality with its <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/css-conditional-3/#at-ruledef-media">@media</a> and <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/css-cascade-4/#at-ruledef-import">@import</a> rules,
ad 87F2 ding the ability to query the value of individual features:</p>
<div class="example" id="example-1a2ad41a"><a class="self-link" href="#example-1a2ad41a"></a>
Inside a CSS style sheet,
one can declare that sections apply to certain <a data-link-type="dfn" href="#media-type">media types</a>:
<pre>@media screen {
* { font-family: sans-serif }
}
</pre>
<p>Similarly, stylesheets can be conditionally imported based on media queries:</p>
<pre>@import "print-styles.css" print;</pre>
</div>
<p><a data-link-type="dfn" href="#media-query">Media queries</a> can be used with HTML, XHTML, XML <a data-link-type="biblio" href="#biblio-xmlstyle">[XMLSTYLE]</a> and the @import and @media rules of CSS.</p>
<div class="example" id="example-b5f134f7"><a class="self-link" href="#example-b5f134f7"></a>
Here is the same example written in HTML, XHTML, XML, @import and @media:
<pre>&lt;link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css">
&lt;link media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" />
&lt;?xml-stylesheet media="screen and (color), projection and (color)"
rel="stylesheet" href="example.css" ?>
@import url(example.css) screen and (color), projection and (color);
@media screen and (color), projection and (color) { … }
</pre>
<p class="note" role="note">Note: The <a data-link-type="biblio" href="#biblio-xmlstyle">[XMLSTYLE]</a> specification has not yet been updated to
use media queries in the <code>media</code> pseudo-attribute.</p>
</div>
<h3 class="heading settled" data-level="1.1" id="placement"><span class="secno">1.1. </span><span class="content">
Module interactions</span><a class="self-link" href="#placement"></a></h3>
<p>This module replaces and extends the Media Queries, Media Type and Media Features
defined in <a data-link-type="biblio" href="#biblio-css21">[CSS21]</a> sections 7 and in <a data-link-type="biblio" href="#biblio-mediaq">[MEDIAQ]</a>.</p>
<h3 class="heading settled" data-level="1.2" id="values"><span class="secno">1.2. </span><span class="content">
Values</span><a class="self-link" href="#values"></a></h3>
<p>Value types not defined in this specification, such as <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value">&lt;integer></a>,
<a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#number-value">&lt;number></a> or <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#resolution-value">&lt;resolution></a>, are defined in <a data-link-type="biblio" href="#biblio-css3val">[CSS3VAL]</a>. Other CSS
modules may expand the definitions of these value types.</p>
<p>This specification also introduces some new value types.</p>
<p>The <dfn class="css" data-dfn-type="type" data-export="" id="typedef-ratio">&lt;ratio><a class="self-link" href="#typedef-ratio"></a></dfn> value type is a positive (not zero or negative)
<a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value" title="Expands to: ">&lt;integer></a> followed by optional whitespace, followed by a solidus ('/'),
followed by optional whitespace, followed by a positive <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value" title="Expands to: ">&lt;integer></a>.
<a class="production css" data-link-type="type" href="#typedef-ratio">&lt;ratio></a>s can be ordered or compared by transforming them into the number
obtained by dividing their first <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value" title="Expands to: ">&lt;integer></a> by their second <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value" title="Expands to: ">&lt;integer></a>.</p>
<p>The <dfn class="css" data-dfn-type="type" data-export="" id="typedef-mq-boolean">&lt;mq-boolean><a class="self-link" href="#typedef-mq-boolean"></a></dfn> value type is an <a class="production css" data-link-type="type" href="http://dev.w3.org/csswg/css-values-3/#integer-value" title="Expands to: ">&lt;integer></a>
with the value <span class="css">0</span> or <span class="css">1</span>.
Any other integer value is invalid.
<span class="note" role="note">Note that <span class="css">-0</span> is always equivalent to <span class="css">0</span> in CSS,
and so is also accepted as a valid <a class="production css" data-link-type="type" href="#typedef-mq-boolean">&lt;mq-boolean></a> value.</span></p>
<h3 class="heading settled" data-level="1.3" id="units"><span class="secno">1.3. </span><span class="content">
Units</span><a class="self-link" href="#units"></a></h3>
<p>The units used in media queries are the same as in other parts of CSS, as
defined in <a data-link-type="biblio" href="#biblio-css3val">[CSS3VAL]</a>. 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 <span class="css">em</span> unit is relative to the initial value of <a class="property" data-link-type="propdesc" href="http://dev.w3.org/csswg/css-fonts-3/#propdef-font-size">font-size</a>,
defined by the user agent or the user’s preferences,
not any styling on the page.</p>
<h2 class="heading settled" data-level="2" id="media"><span class="secno">2. </span><span class="content">
Media Queries</span><a class="self-link" href="#media"></a></h2>
<p>A <dfn data-dfn-type="dfn" data-export="" id="media-query">media query<a class="self-link" href="#media-query"></a></dfn> is a method of testing certain aspects of the user agent
or device that the document is being displayed in.
<a data-link-type="dfn" href="#media-query">Media queries</a> are (almost) always independent of the contents of the document,
its styling,
or any other internal aspect;
they’re only dependent on “external” information
unless another feature explicitly specifies that it affects the resolution of Media Queries,
such as the <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/css-device-adapt-1/#at-ruledef-viewport">@viewport</a> rule.</p>
<p>The syntax of a <a data-link-type="dfn" href="#media-query">media query</a> consists of
an optional <a data-link-type="dfn" href="#media-query-modifier">media query modifier</a>,
an optional <a data-link-type="dfn" href="#media-type">media type</a>,
and zero or more <a data-link-type="dfn" href="#media-feature">media features</a>:</p>
<div class="railroad">
<svg class="railroad-diagram" height="150" viewBox="0 0 597 150" width="597">
<g transform="translate(.5 .5)">
<path d="M 20 21 v 20 m 10 -20 v 20 m -10 -10 h 20.5" data-type="start" data-updown="10 10">
</path>
<g data-type="choice" data-updown="11 99">
<path d="M40 31h0.0">
</path>
<path d="M556.0 31h0.0">
</path>
<path d="M40.0 31h20">
</path>
<path d="M536.0 31h20">
</path>
<g data-type="non-terminal" data-updown="11 11">
<path d="M60.0 31h168.0">
</path>
<path d="M368.0 31h168.0">
</path>
<rect height="22" width="140" x="228.0" y="20">
</rect>
<text x="298.0" y="35">
media condition</text></g>
<path d="M40.0 31a10 10 0 0 1 10 10v39a10 10 0 0 0 10 10">
</path>
<path d="M536.0 90a10 10 0 0 0 10 -10v-39a10 10 0 0 1 10 -10">
</path>
<g data-type="sequence" data-updown="40 40">
<path d="M60.0 90h0.0">
</path>
<path d="M536.0 90h0.0">
</path>
<g data-type="choice" data-updown="40 40">
<path d="M60.0 90h0.0">
</path>
<path d="M152.0 90h0.0">
</path>
<path d="M60.0 90a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path>
<path d="M132.0 70a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path>
<g data-type="terminal" data-updown="11 11">
<path d="M80.0 70h0.0">
</path>
<path d="M132.0 70h0.0">
</path>
<rect height="22" rx="10" ry="10" width="52" x="80.0" y="59">
</rect>
<text x="106.0" y="74">
only</text></g>
<path d="M60.0 90h20">
</path>
<path d="M132.0 90h20">
</path>
<g data-type="skip" data-updown="0 0">
<path d="M80.0 90h52">
</path></g>
<path d="M60.0 90a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path>
<path d="M132.0 110a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path>
<g data-type="terminal" data-updown="11 11">
<path d="M80.0 110h4.0">
</path>
<path d="M128.0 110h4.0">
</path>
<rect height="22" rx="10" ry="10" width="44" x="84.0" y="99">
</rect>
<text x="106.0" y="114">
not</text></g></g>
<path d="M152.0 90h10">
</path>
<path d="M262.0 90h10">
</path>
<g data-type="non-terminal" data-updown="11 11">
<path d="M162.0 90h0.0">
</path>
<path d="M262.0 90h0.0">
</path>
<rect height="22" width="100" x="162.0" y="79">
</rect>
<text x="212.0" y="94">
media type</text></g>
<g data-type="choice" data-updown="21 11">
<path d="M272.0 90h0.0">
</path>
<path d="M536.0 90h0.0">
</path>
<path d="M272.0 90a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path>
<path d="M516.0 70a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path>
<g data-type="skip" data-updown="0 0">
<path d="M292.0 70h224">
</path></g>
<path d="M272.0 90h20">
</path>
<path d="M516.0 90h20">
</path>
<g data-type="sequence" data-updown="11 11">
<path d="M292.0 90h0.0">
</path>
<path d="M516.0 90h0.0">
</path>
<path d="M292.0 90h10">
</path>
<path d="M346.0 90h10">
</path>
<g data-type="terminal" data-updown="11 11">
<path d="M302.0 90h0.0">
</path>
<path d="M346.0 90h0.0">
</path>
<rect height="22" rx="10" ry="10" width="44" x="302.0" y="79">
</rect>
<text x="324.0" y="94">
and</text></g>
<path d="M356.0 90h10">
</path>
<path d="M506.0 90h10">
</path>
<g data-type="non-terminal" data-updown="11 11">
<path d="M366.0 90h0.0">
</path>
<path d="M506.0 90h0.0">
</path>
<rect height="22" width="140" x="366.0" y="79">
</rect>
<text x="436.0" y="94">
media condition</text></g></g></g></g></g>
<path d="M 556 31 h 20 m -10 -10 v 20 m 10 -20 v 20" data-type="end" data-updown="10 10">
</path></g>
</svg></div>
<p>A <a data-link-type="dfn" href="#media-query">media query</a> is a logical expression that is either true or false.
A media query is true if:</p>
<ul>
<li data-md="">
<p>the <a data-link-type="dfn" href="#media-type">media type</a>,
if specified,
matches the media type of the device where the user agent is running, and</p>
<li data-md="">
<p>the <a data-link-type="dfn" href="#media-condition">media condition</a> is true.</p>
</ul>
<p>Statements regarding media queries in this section assume the <a href="#mq-syntax">syntax section</a> is followed.
Media queries that do not conform to the syntax are discussed in <a href="#error-handling">§3.1
Error Handling</a>.
I.e. the syntax takes precedence over requirements in this section.</p>
<div class="example" id="example-3d9b3047"><a class="self-link" href="#example-3d9b3047"></a>
Here is a simple example written in HTML:
<pre>&lt;link rel="stylesheet" media="screen and (color)" href="example.css" /></pre>
<p>This example expresses that a certain style sheet
(<code>example.css</code>) applies to devices of a certain media type
(<a class="css" data-link-type="maybe" href="#valdef-media-screen">screen</a>) with certain feature (it must be a color screen).</p>
<p>Here is the same media query written in an @import-rule in CSS:</p>
<pre>@import url(example.css) screen and (color);</pre>
</div>
<p>User agents must re-evaluate <a data-link-type="dfn" href="#media-query">media queries</a> in response to changes in the user environment that they’re aware of,
for example if the device is tiled from landscape to portrait orientation,
and change the behavior of any constructs dependent on those <a data-link-type="dfn" href="#media-query">media queries</a> accordingly.</p>
<p>Unless another feature explicitly specifies that it affects the resolution of Media Queries, it is never necessary to apply a style sheet in order to evaluate expressions.</p>
<p class="note" role="note">Note: CSS Device Adaptation <a data-link-type="biblio" href="#biblio-css-device-adapt">[CSS-DEVICE-ADAPT]</a>]
defines how <a class="css" data-link-type="maybe" href="http://dev.w3.org/csswg/css-device-adapt-1/#at-ruledef-viewport">@viewport</a> rules interact with Media Queries.</p>
<h3 class="heading settled" data-level="2.1" id="mq-list"><span class="secno">2.1. </span><span class="content">
Combining Media Queries</span><a class="self-link" href="#mq-list"></a></h3>
<p>Several <a data-link-type="dfn" href="#media-query">media queries</a> can be combined into a comma-separated <dfn data-dfn-type="dfn" data-export="" id="media-query-list">media query list<a class="self-link" href="#media-query-list"></a></dfn>.</p>
<div class="railroad">
<svg class="railroad-diagram" height="102" viewBox="0 0 249 102" width="249">
<g transform="translate(.5 .5)">
<path d="M 20 31 v 20 m 10 -20 v 20 m -10 -10 h 20.5" data-type="start" data-updown="10 10">
</path>
<g data-type="choice" data-updown="21 41">
<path d="M40 41h0.0">
</path>
<path d="M208.0 41h0.0">
</path>
<path d="M40.0 41a10 10 0 0 0 10 -10v0a10 10 0 0 1 10 -10">
</path>
<path d="M188.0 21a10 10 0 0 1 10 10v0a10 10 0 0 0 10 10">
</path>
<g data-type="skip" data-updown="0 0">
<path d="M60.0 21h128">
</path></g>
<path d="M40.0 41h20">
</path>
<path d="M188.0 41h20">
</path>
<g data-type="oneormore" data-updown="11 41">
<path d="M60.0 41h0.0">
</path>
<path d="M188.0 41h0.0">
</path>
<path d="M60.0 41h10">
</path>
<path d="M178.0 41h10">
</path>
<path d="M70.0 41a10 10 0 0 0 -10 10v10a10 10 0 0 0 10 10">
</path>
<path d="M178.0 71a10 10 0 0 0 10 -10v-10a10 10 0 0 0 -10 -10">
</path>
<g data-type="non-terminal" data-updown="11 11">
<path d="M70.0 41h0.0">
</path>
<path d="M178.0 41h0.0">
</path>
<rect height="22" width="108" x="70.0" y="30">
</rect>
<text x="124.0" y="45">
media query</text></g>
<g data-type="terminal" data-updown="11 11">
<path d="M70.0 71h40.0">
</path>
<path d="M138.0 71h40.0">
</path>
<rect height="22" rx="10" ry="10" width="28" x="110.0" y="60">
</rect>
<text x="124.0" y="75">
,</text></g></g></g>
<path d="M 208 41 h 20 m -10 -10 v 20 m 10 -20 v 20" data-type="end" data-updown="10 10">
</path></g>
</svg></div>
<p>A <a data-link-type="dfn" href="#media-query-list">media query list</a> is true if <em>any</em> of its component <a data-link-type="dfn" href="#media-query">media queries</a> are true,
and false only if <em>all</em> of its component <a data-link-type="dfn" href="#media-query">media queries</a> are false.</p>
<div class="example" id="example-73f4f21c"><a class="self-link" href="#example-73f4f21c"></a>
For example, the following <a data-link-type="dfn" href="#media-query-list">media query list</a> is true if either
the <a data-link-type="dfn" href="#media-type">media type</a> is <a class="css" data-link-type="maybe" href="#valdef-media-screen">screen</a> and it’s a color device,
<strong>or</strong> the <a data-link-type="dfn" href="#media-type">media type</a> is <a class="css" data-link-type="maybe" href="#valdef-media-projection">projection</a> and it’s a color device:
<pre>@media screen and (color), projection and (color) { … }
</pre>
</div>
<p>An empty <a data-link-type="dfn" href="#media-query-list">media query list</a> evaluates to true.</p>
<div class="example" id="example-41c0228b"><a class="self-link" href="#example-41c0228b"></a>
For example, these are equivalent:
<pre>@media all { … }
@media { … }
</pre>
</div>
<h3 class="heading settled" data-level="2.2" id="mq-prefix"><span class="secno">2.2. </span><span class="content">
Media Query Modifiers</span><a class="self-link" href="#mq-prefix"></a></h3>
<p>A <a data-link-type="dfn" href="#media-query">media query</a> may optionally be prefixed by a single <dfn data-dfn-type="dfn" data-export="" id="media-query-modifier">media query modifier<a class="self-link" href="#media-query-modifier"></a></dfn>,
which is a single keyword which alters the meaning of the following <a data-link-type="dfn" href="#media-query">media query</a>.</p>
<h4 class="heading settled" data-level="2.2.1" id="mq-not"><span class="secno">2.2.1. </span><span class="content">
Negating a Media Query: the <a class="css" data-link-type="maybe" href="#valdef-media-not">not</a> keyword</span><a class="self-link" href="#mq-not"></a></h4>
<p>An individual <a data-link-type="dfn" href="#media-query">media query</a> can have its result negated
by prefixing it with the keyword <dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-not">not<a class="self-link" href="#valdef-media-not"></a></dfn>.
If the <a data-link-type="dfn" href="#media-query">media query</a> would normally evaluate to true,
prefixing it with <a class="css" data-link-type="maybe" href="#valdef-media-not">not</a> makes it evaluate to false,
and vice versa.</p>
<div class="example" id="example-9a75128e"><a class="self-link" href="#example-9a75128e"></a>
For example, the following will apply to everything except color-capable screens.
Note that the entire media query is negated,
not just the <a data-link-type="dfn" href="#media-type">media type</a>.
<pre>&lt;link rel="stylesheet" media="not screen and (color)" href="example.css" /></pre>
</div>
<h4 class="heading settled" data-level="2.2.2" id="mq-only"><span class="secno">2.2.2. </span><span class="content">
Hiding a Media Query From Legacy User Agents: the <a class="css" data-link-type="maybe" href="#valdef-media-only">only</a> keyword</span><a class="self-link" href="#mq-only"></a></h4>
<p>The concept of <a data-link-type="dfn" href="#media-query">media queries</a> originates from HTML4 <a data-link-type="biblio" href="#biblio-html401">[HTML401]</a>.
That specification only defined <a data-link-type="dfn" href="#media-type">media types</a>,
but had a forward-compatible syntax that accommodated the addition of future concepts like <a data-link-type="dfn" href="#media-feature">media features</a>:
it would consume the characters of a <a data-link-type="dfn" href="#media-query">media query</a> up to the first non-alphanumeric character,
and interpret that as a <a data-link-type="dfn" href="#media-type">media type</a>,
ignoring the rest.
For example, the <a data-link-type="dfn" href="#media-query">media query</a> <span class="css">screen and (color)</span>
would be truncated to just <a class="css" data-link-type="maybe" href="#valdef-media-screen">screen</a>.</p>
<p>Unfortunately, this means that legacy user agents using this error-handling behavior
will ignore any <a data-link-type="dfn" href="#media-feature">media features</a> in a <a data-link-type="dfn" href="#media-query">media query</a>,
even if they’re far more important than the <a data-link-type="dfn" href="#media-type">media type</a> in the query.
This can result in styles accidentally being applied in inappropriate situations.</p>
<p>To hide these <a data-link-type="dfn" href="#media-query">media queries</a> from legacy user agents,
the <a data-link-type="dfn" href="#media-query">media query</a> can be prefixed with the keyword <dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-only">only<a class="self-link" href="#valdef-media-only"></a></dfn>.
The <a class="css" data-link-type="maybe" href="#valdef-media-only">only</a> keyword <strong>has no effect</strong> on the <a data-link-type="dfn" href="#media-query">media query</a>’s result,
but will cause the <a data-link-type="dfn" href="#media-query">media query</a> to be parsed by legacy user agents
as specifying the unknown <a data-link-type="dfn" href="#media-type">media type</a> “only”,
and thus be ignored.</p>
<div class="example" id="example-5f9554b4"><a class="self-link" href="#example-5f9554b4"></a>
In this example, the stylesheet specified by the <code>&lt;link></code> element
will not be used by legacy user agents,
even if they would normally match the <a class="css" data-link-type="maybe" href="#valdef-media-screen">screen</a> <a data-link-type="dfn" href="#media-type">media type</a>.
<pre>&lt;link rel="stylesheet" media="only screen and (color)" href="example.css" /></pre>
</div>
<p class="note" role="note">Note: Note that the <a class="css" data-link-type="maybe" href="#valdef-media-only">only</a> keyword can only be used before a <a data-link-type="dfn" href="#media-type">media type</a>.
A <a data-link-type="dfn" href="#media-query">media query</a> consisting only of <a data-link-type="dfn" href="#media-feature">media features</a>,
or one with another <a data-link-type="dfn" href="#media-query-modifier">media query modifier</a> like <a class="css" data-link-type="maybe" href="#valdef-media-not">not</a>,
will be treated as false by legacy user agents automatically.</p>
<p class="note" role="note">Note: At the time of publishing this specification,
such legacy user agents are extremely rare,
and so using the <a class="css" data-link-type="maybe" href="#valdef-media-only">only</a> modifier is rarely, if ever, necessary.</p>
<h3 class="heading settled" data-level="2.3" id="media-types"><span class="secno">2.3. </span><span class="content">
Media Types</span><a class="self-link" href="#media-types"></a></h3>
<p>A <dfn data-dfn-type="dfn" data-export="" id="media-type">media type<a class="self-link" href="#media-type"></a></dfn> is a broad category of user-agent devices
on which a document may be displayed.
The original set of <a data-link-type="dfn" href="#media-type">media types</a> were defined in HTML4,
for the <code>media</code> attribute on <code>&lt;link></code> elements.</p>
<p>Unfortunately, <a data-link-type="dfn" href="#media-type">media types</a> have proven insufficient as a way of discriminating between devices with different styling needs.
Some categories which were originally quite distinct,
such as <a class="css" data-link-type="maybe" href="#valdef-media-screen">screen</a> and <a class="css" data-link-type="maybe" href="#valdef-media-handheld">handheld</a>,
have blended significantly in the years since their invention.
Others, such as <a class="css" data-link-type="maybe" href="#valdef-media-tty">tty</a> or <a class="css" data-link-type="maybe" href="#valdef-media-tv">tv</a>,
expose useful differences from the norm of a full-featured computer monitor,
and so are potentially useful to target with different styling,
but the definition of <a data-link-type="dfn" href="#media-type">media types</a> as mutually exclusive
makes it difficult to use them in a reasonable manner;
instead, their exclusive aspects are better expressed as <a data-link-type="dfn" href="#media-feature">media features</a>
such as <a class="property" data-link-type="propdesc" href="#descdef-media-grid">grid</a> or <a class="property" data-link-type="propdesc" href="#descdef-media-scan">scan</a>.</p>
<p>As such, the following <a data-link-type="dfn" href="#media-type">media types</a> are defined for use in <a data-link-type="dfn" href="#media-query">media queries</a>:</p>
<dl>
<dt><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-all">all<a class="self-link" href="#valdef-media-all"></a></dfn>
<dd>Matches all devices.
<dt><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-print">print<a class="self-link" href="#valdef-media-print"></a></dfn>
<dd>Matches printers, and devices intended to reproduce a printed display,
such as a web browser showing a document in “Print Preview”.
<dt><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-screen">screen<a class="self-link" href="#valdef-media-screen"></a></dfn>
<dd>Matches all devices that aren’t matched by <a class="css" data-link-type="maybe" href="#valdef-media-print">print</a> or <a class="css" data-link-type="maybe" href="#valdef-media-speech">speech</a>.
<dt><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-speech">speech<a class="self-link" href="#valdef-media-speech"></a></dfn>
<dd>Matches screenreaders and similar devices that “read out” a page.
</dl>
<p>In addition, the following <strong>deprecated</strong> <a data-link-type="dfn" href="#media-type">media types</a> are defined.
Authors must not use these <a data-link-type="dfn" href="#media-type">media types</a>;
instead, it is recommended that they select appropriate <a data-link-type="dfn" href="#media-feature">media features</a>
that better represent the aspect of the device that they are attempting to style against.</p>
<p>User agents must recognize the following <a data-link-type="dfn" href="#media-type">media types</a> as valid,
but must make them match nothing.</p>
<ul>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-tty">tty<a class="self-link" href="#valdef-media-tty"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-tv">tv<a class="self-link" href="#valdef-media-tv"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-projection">projection<a class="self-link" href="#valdef-media-projection"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-handheld">handheld<a class="self-link" href="#valdef-media-handheld"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-braille">braille<a class="self-link" href="#valdef-media-braille"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-embossed">embossed<a class="self-link" href="#valdef-media-embossed"></a></dfn>
<li><dfn class="css" data-dfn-for="@media" data-dfn-type="value" data-export="" id="valdef-media-aural">aural<a class="self-link" href="#valdef-media-aural"></a></dfn>
</ul 18B9 >
<p class="note" role="note">Note: It is expected that all of the media types will also be deprecated in time,
as appropriate <a data-link-type="dfn" href="#media-feature">media features</a> are defined which capture their important differences.</p>
<h3 class="heading settled" data-level="2.4" id="mq-features"><span class="secno">2.4. </span><span class="content">
Media Features</span><a class="self-link" href="#mq-features"></a></h3>
<p>A <dfn data-dfn-type="dfn" data-export="" id="media-feature">media feature<a class="self-link" href="#media-feature"></a></dfn> is a more fine-grained test than <a data-link-type="dfn" href="#media-type">media types</a>,
testing a single, specific feature of the user agent or display device.</p>
<p>Syntactically, <a data-link-type="dfn" href="#media-feature">media features</a> resemble CSS properties:
they consist of a feature name, a colon, and a value to test for.
They may also be written in boolean form as just a feature name,
or in range form with a comparison operator.</p>