Skip to content

Commit 5f2781a

Browse files
committed
Create a Media Queries 5 specification
Reinstate the content that was taken out of Level 4, and add 'prefers-reduced-motion'.
1 parent 4d50007 commit 5f2781a

File tree

1 file changed

+331
-0
lines changed

1 file changed

+331
-0
lines changed

mediaqueries-5/Overview.bs

Lines changed: 331 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,331 @@
1+
<pre class='metadata'>
2+
Title: Media Queries Level 5
3+
Group: csswg
4+
Shortname: mediaqueries
5+
Level: 5
6+
Status: ED
7+
Work Status: Exploring
8+
ED: https://drafts.csswg.org/mediaqueries-5/
9+
TR:
10+
Previous Version:
11+
Editor: Dean Jackson, Apple
12+
Editor: Florian Rivoal, Vivliostyle, http://florian.rivoal.net, http://vivliostyle.com, w3cid 43241
13+
Editor: Tab Atkins Jr., Google, http://xanthir.com/contact/, w3cid 42199
14+
Abstract: <a>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.
15+
Abstract:
16+
Abstract: Media Queries Level 5 describes the mechanism and syntax of media queries, media types, and media features. It extends and supersedes the features defined in Media Queries Level 4.
17+
Ignored Terms: min-resolution, max-resolution, none, view-mode, mediaText, DOMString
18+
Link Defaults: css-break-3 (property) break-inside
19+
Link Defaults: css-cascade-3 (at-rule) @import
20+
</pre>
21+
22+
<pre class=link-defaults>
23+
spec:css-values-3; type:value; text:in
24+
</pre>
25+
26+
<!--
27+
████████ ██ ██ ██ ██
28+
██ ███ ██ ██ ██
29+
██ ████ ██ ██ ██
30+
██████ ██ ██ ██ ██ ██
31+
██ ██ ████ ██ ██
32+
██ ██ ███ ██ ██
33+
████████ ██ ██ ███
34+
-->
35+
36+
<h2 id='mf-environment'>
37+
Environment Media Features</h2>
38+
39+
<h3 id="light-level">
40+
Detecting the ambient light level: the 'light-level' feature</h3>
41+
42+
<pre class='descdef mq'>
43+
Name: light-level
44+
Value: dim | normal | washed
45+
For: @media
46+
Type: discrete
47+
</pre>
48+
49+
The 'light-level' media feature is used to query about the ambient light-level in which the device is used,
50+
to allow the author to adjust style of the document in response.
51+
The following values are valid:
52+
53+
<dl dfn-type=value dfn-for="@media/light-level">
54+
<dt><dfn>dim</dfn>
55+
<dd>
56+
The device is used in a dim environment,
57+
where excessive contrast and brightness would be distracting or uncomfortable to the reader.
58+
For example: night time, or a dimly illuminated indoor environment.
59+
60+
<dt><dfn>normal</dfn>
61+
<dd>
62+
The device is used in a environment with a light level in the ideal range for the screen,
63+
and which does not necessitate any particular adjustment.
64+
65+
<dt><dfn>washed</dfn>
66+
<dd>
67+
The device is used in an exceptionally bright environment,
68+
causing the screen to be washed out and difficult to read.
69+
For example: bright daylight.
70+
</dl>
71+
72+
User agents should set the thresholds between the three levels
73+
in a way that takes into account the characteristics of the device.
74+
75+
<div class="note">
76+
Even though it is expected that User Agents will adjust the value of this media feature
77+
based on ambient light sensors,
78+
this specification intentionally refrains from defining the three levels in terms of a measurement in lux,
79+
for several reasons:
80+
81+
<ul>
82+
<li>
83+
Devices equipped with a light sensor usually adjust the brightness of the screen automatically.
84+
Depending on the level of adjustment,
85+
the thresholds for needing a low contrast or hight contrast content may vary.
86+
87+
<li>
88+
Different screen technologies wash out at very different ambient light levels;
89+
e-ink displays remain readable in bright daylight,
90+
while liquid crystal displays do not.
91+
92+
<li>
93+
Many embedded light sensors are inaccurately calibrated,
94+
making it difficult to establish useful thresholds valid across devices.
95+
</ul>
96+
</div>
97+
98+
For accessibility purposes, user agents may offer manual controls
99+
allowing the user to switch between the three levels of independently of the ambient light level,
100+
as high contrast or low contrast styles may be more suitable for users with visual disabilities.
101+
102+
<p class="issue">
103+
Using this media feature for accessibility purposes overlaps a lot with <a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh465764.aspx">the high-contrast media feature proposed by Microsoft</a>.
104+
Can we adjust this so that it covers all use cases for both,
105+
or somehow modify them to work in an orthogonal, rather than overlapping, fashion?
106+
107+
<div class="example">
108+
<pre>
109+
@media (light-level: normal) {
110+
p { background: url("texture.jpg"); color: #333 }
111+
}
112+
@media (light-level: dim) {
113+
p { background: #222; color: #ccc }
114+
}
115+
@media (light-level: washed) {
116+
p { background: white; color: black; font-size: 2em; }
117+
}
118+
</pre>
119+
</div>
120+
121+
122+
<!--
123+
██████ ██ ██ ██████ ████████ ███████ ██ ██ ██ ██ ███████
124+
██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ███ ███ ███ ██ ██
125+
██ ██ ██ ██ ██ ██ ██ ████ ████ ████ ████ ██ ██
126+
██ ██ ██ ██████ ██ ██ ██ ██ ███ ██ ██ ███ ██ ██ ██
127+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
128+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
129+
██████ ███████ ██████ ██ ███████ ██ ██ ██ ██ █████ ██
130+
-->
131+
132+
<h2 id='custom-mq'>
133+
Custom Media Queries</h2>
134+
135+
When designing documents that use media queries,
136+
the same media query may be used in multiple places,
137+
such as to qualify multiple ''@import'' statements.
138+
Repeating the same media query multiple times is an editing hazard;
139+
an author making a change must edit every copy in the same way,
140+
or suffer from difficult-to-find bugs in their CSS.
141+
142+
To help ameliorate this,
143+
this specification defines a method of defining <a>custom media queries</a>,
144+
which are simply-named aliases for longer and more complex media queries.
145+
In this way, a media query used in multiple places can instead be assigned to a <a>custom media query</a>,
146+
which can be used everywhere,
147+
and editing the media query requires touching only one line of code.
148+
149+
A <dfn>custom media query</dfn> is defined with the ''@custom-media'' rule:
150+
151+
<pre class='prod'>
152+
<dfn>@custom-media</dfn> = @custom-media <<extension-name>> [ <<media-query-list>> | true | false ] ;
153+
</pre>
154+
155+
The <<extension-name>> can then be used in a <a>media feature</a>.
156+
It <strong>must</strong> be used in a <a>boolean context</a>;
157+
using them in a normal or <a>range context</a> is a syntax error.
158+
If a <<media-query-list>> is given,
159+
the <a>custom media query</a> evaluates to true
160+
if the <<media-query-list>> it represents evaluates to true,
161+
and false otherwise.
162+
If <dfn value for="@custom-media">true</dfn> or <dfn value for="@custom-media">false</dfn> is given,
163+
the <a>custom media query</a> evaluates to true or false, respectively.
164+
165+
A ''@custom-media'' rule can refer to other <a>custom media queries</a>.
166+
However, loops are forbidden,
167+
and a <a>custom media query</a> must not be defined in terms of itself or
168+
of another <a>custom media query</a> that directly or indirectly refers to it.
169+
Any such attempt of defining a <a>custom media query</a> with a circular dependency
170+
must cause all the <a>custom media queries</a> in the loop to fail to be defined.
171+
172+
Note: For error handling purposes,
173+
an undefined <a>media feature</a> is different from
174+
a <a>media feature</a> that evaluates to false.
175+
See <a href="#error-handling">Error Handling</a> for details.
176+
177+
<div class='example'>
178+
For example, if a responsive site uses a particular breakpoint in several places,
179+
it can alias that with a reasonable name:
180+
181+
<pre>
182+
@custom-media --narrow-window (max-width: 30em);
183+
184+
@media (--narrow-window) {
185+
/* narrow window styles */
186+
}
187+
@media (--narrow-window) and (script) {
188+
/* special styles for when script is allowed */
189+
}
190+
/* etc */
191+
</pre>
192+
</div>
193+
194+
<h3 id='script-custom-mq'>
195+
Script-based Custom Media Queries</h3>
196+
197+
<div class='issue'>
198+
Define a map of names to values for JS.
199+
Values can be either a MediaQueryList object or a boolean,
200+
in which case it's treated identically to the above,
201+
or can be a number or a string,
202+
in which case it's treated like a normal MQ,
203+
and can use the normal or range context syntax.
204+
Like:
205+
206+
<pre>
207+
&lt;script>
208+
CSS.customMedia.set('--foo', 5);
209+
&lt;/script>
210+
&lt;style>
211+
@media (_foo: 5) { ... }
212+
@media (_foo < 10) { ... }
213+
&lt;/style>
214+
</pre>
215+
</div>
216+
217+
218+
<!--
219+
██ ██ ██████ ████████ ████████ ████████ ████████ ████████ ████████ ██████
220+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
221+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
222+
██ ██ ██████ ██████ ████████ ████████ ████████ ██████ ██████ ██████
223+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
224+
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
225+
███████ ██████ ████████ ██ ██ ██ ██ ██ ████████ ██ ██████
226+
-->
227+
228+
<h2 id='mf-user-preferences'>
229+
User Preference Media Features</h2>
230+
231+
<h3 id="inverted">
232+
Detecting the desire for inverted colors on the display: the 'inverted-colors' feature</h3>
233+
234+
<pre class='descdef mq'>
235+
Name: inverted-colors
236+
Value: none | inverted
237+
For: @media
238+
Type: discrete
239+
</pre>
240+
241+
The 'inverted-colors' media feature indicates whether the content is displayed normally, or whether colors have been inverted.
242+
243+
Note: This is an indication that the user agent or underlying
244+
operating system has forcibly inverted all colors, not a request to do so. This
245+
is sometimes provided as a simple accessibility feature, allowing users to
246+
switch between light-on-dark and dark-on-light text. However, this has
247+
unpleasant side effects, such as inverting pictures, or turning shadows into
248+
highlights, which reduce the readability of the content.
249+
250+
<dl dfn-type=value dfn-for="@media/inverted-colors">
251+
<dt><dfn>none</dfn>
252+
<dd>
253+
Colors are displayed normally.
254+
255+
<dt><dfn>inverted</dfn>
256+
<dd>
257+
All pixels within the displayed area have been inverted.
258+
259+
</dl>
260+
261+
<div class="example">
262+
For example, a user frequently using their operating system's ability to invert the screens color
263+
may want to add the following to their user style sheet,
264+
to limit the undesirable side effects of the inversion.
265+
266+
<pre>
267+
@media (inverted-colors) {
268+
img { filter: invert(100%); }
269+
* { text-shadow: none; box-shadow: none; }
270+
}
271+
</pre>
272+
</div>
273+
274+
<h3 id="prefers-reduced-motion">
275+
Detecting the desire for less motion on the page: the 'prefers-reduced-motion' feature</h3>
276+
277+
<pre class='descdef mq'>
278+
Name: prefers-reduced-motion
279+
Value: no-preference | reduce
280+
For: @media
281+
Type: discrete
282+
</pre>
283+
284+
The 'prefers-reduced-motion' media feature is used to detect if the user
285+
has requested the system minimize the amount of animation or motion it
286+
uses.
287+
288+
<dl dfn-type=value dfn-for="@media/prefers-reduced-motion">
289+
<dt><dfn>no-preference</dfn>
290+
<dd>
291+
Indicates that the user has made no preference known
292+
to the system. This keyword value evaluates as false
293+
in the <a>boolean context</a>.
294+
295+
<dt><dfn>reduce</dfn>
296+
<dd>
297+
Indicates that user has notified the system that they
298+
prefer an interface that minimizes the amount of movement
299+
or animation, preferably to the point where all non-essential
300+
movement is removed.
301+
302+
</dl>
303+
304+
<h2 id="changes" class="no-num">
305+
Changes</h2>
306+
<h3 id="changes-2017">
307+
Changes Since the Media Queries Level 4</h3>
308+
309+
The following changes were made to this specification since the
310+
<a href="https://www.w3.org/TR/mediaqueries-4/">6 July 20126 Working Draft of Media Queries Level 4</a>:
311+
312+
<ul>
313+
<li>
314+
Reinstate 'light-level', 'inverted-colors' and Custom Media Queries sections from the
315+
Media Queries Level 4 drafts.
316+
317+
<li>
318+
Add 'prefers-reduced-motion' media feature.
319+
</ul>
320+
321+
322+
<h2 class="no-num" id="acknowledgments">
323+
Acknowledgments</h2>
324+
325+
This specification is the product of the W3C Working Group on
326+
Cascading Style Sheets.
327+
328+
Comments from
329+
James Craig
330+
improved this specification.
331+

0 commit comments

Comments
 (0)