Skip to content

Commit 5d07e24

Browse files
committed
[css-color-adjust-1] Per WG resolution in w3c#3881, remove the 'only' keyword from 'color-scheme', and adjust the resolution rules to always respect author preference. Since the used color scheme resolution rules are now simple enough to inline, remove the table and the algorithm. Also add some examples highlighting good practice.
1 parent 1d2fd71 commit 5d07e24

1 file changed

Lines changed: 70 additions & 126 deletions

File tree

css-color-adjust-1/Overview.bs

Lines changed: 70 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -108,94 +108,60 @@ Opting Into a Preferred Color Scheme: the 'color-scheme' property {#color-scheme
108108

109109
<pre class=propdef>
110110
Name: color-scheme
111-
Value: normal | [ light | dark | <<custom-ident>> ]+ | only && light
111+
Value: normal | [ light | dark | <<custom-ident>> ]+
112112
Initial: normal
113113
Applies to: all elements
114114
Inherited: yes
115-
Computed Value: the keyword ''normal'', or optional ''only'' keyword and ordered list of specified color scheme keywords
115+
Computed Value: the keyword ''normal'', or an ordered list of specified color scheme keywords
116116
</pre>
117117

118118
The 'color-scheme' property allows an element to indicate
119119
which [=color schemes=] it is comfortable being rendered with.
120-
These values are negotiated with the users preferences,
121-
resulting in a chosen [=color scheme=]
120+
These values are negotiated with the user's preferences,
121+
resulting in a <dfn>used color scheme</dfn>
122122
that affects UI things such as
123123
the default colors of form controls and scrollbars
124124
as well as the used values of the CSS system colors.
125125

126-
127-
<table class="data">
128-
<caption>Interaction of author and user preferences in determining [=used color scheme=] (non-normative)</caption>
129-
<colgroup span=2></colgroup>
130-
<colgroup span=3></colgroup>
131-
<thead>
132-
<tr>
133-
<td colspan=2 rowspan=2>
134-
<th colspan=3>User Preference ('prefers-color-scheme')
135-
<tr>
136-
<th>''@media/prefers-color-scheme/no-preference''
137-
<th>''@media/prefers-color-scheme/light''
138-
<th>''@media/prefers-color-scheme/dark''
139-
<tbody>
140-
<tr>
141-
<th rowspan=7 style="width: 1.2em; writing-mode: vertical-rl; writing-mode: sideways-lr">Author Preference ('color-scheme')
142-
<th>''color-scheme/normal''
143-
<td>default
144-
<td>default
145-
<td>default
146-
<tr>
147-
<th>''color-scheme/light''
148-
<td>light
149-
<td>light
150-
<td>default
151-
<tr>
152-
<th>''color-scheme/dark''
153-
<td>dark
154-
<td>default
155-
<td>dark
156-
<tr>
157-
<th>''color-scheme/light dark''
158-
<td>light
159-
<td>light
160-
<td>dark
161-
<tr>
162-
<th>''color-scheme/dark light''
163-
<td>dark
164-
<td>light
165-
<td>dark
166-
<tr>
167-
<th>''color-scheme/only light''
168-
<td>light
169-
<td>light
170-
<td>light
171-
<tr>
172-
<th>''color-scheme/only dark''
173-
<td>dark
174-
<td>dark
175-
<td>dark
176-
</table>
177-
178126
Values are defined as follows:
179127

180128
<dl dfn-type=value dfn-for=color-scheme>
181129
: <dfn>normal</dfn>
182-
:: Indicates that the element isn't aware of [=color schemes=] at all,
130+
::
131+
Indicates that the element isn't aware of [=color schemes=] at all,
183132
and so the element should be rendered with the browser's default [=color scheme=].
184133

185134
: <dfn lt="light | dark">[ light | dark | <<custom-ident>> ]+</dfn>
186-
:: Indicates that the element is aware of and can handle the listed [=color schemes=],
187-
and expresses an ordered preference between them.
188-
(See [[#color-scheme-processing]] for details on how this choice is resolved.)
135+
::
136+
Indicates that the element is okay with being rendered with any of the listed [=color schemes=].
137+
138+
If the user's preferred color scheme,
139+
as indicated by the 'prefers-color-scheme' media feature,
140+
is present among the listed [=color schemes=],
141+
and is supported by the user agent,
142+
that's the element's [=used color scheme=].
189143

190-
Note: Providing both keywords indicates that the first scheme is preferred,
191-
but the second is also acceptable
192-
if the user prefers it instead.
144+
Otherwise,
145+
if the user agent supports at least one of the listed [=color schemes=],
146+
the [=used color scheme=] is
147+
the first supported [=color scheme=] in the list.
193148

194-
''light'' represents a “Light” [=color scheme=],
149+
Otherwise,
150+
the [=used color scheme=] is the browser default.
151+
(Same as ''color-scheme/normal''.)
152+
153+
''light'' represents a “light” [=color scheme=],
195154
with light background colors and dark foreground colors.
196155
''dark'' represents the opposite,
197156
with dark background colors and light foreground colors.
198157

158+
Note: User agents are <strong>not required</strong>
159+
to support any particular [=color scheme=],
160+
so only using a single keyword,
161+
such as ''color-scheme: dark'',
162+
to indicate a required [=color scheme=]
163+
is still not guaranteed to have any effect on the rendering of the element.
164+
199165
<<custom-ident>> values are meaningless,
200166
and exist only for future compatibility,
201167
so that future added color schemes do not invalidate the 'color-scheme' declaration
@@ -207,81 +173,59 @@ Opting Into a Preferred Color Scheme: the 'color-scheme' property {#color-scheme
207173
authoring tutorials and references
208174
should omit <<custom-ident>> from their materials.
209175

210-
''only'', ''color-scheme/normal'', ''light'', and ''dark'' are not valid <<custom-ident>>s in this property.
176+
''color-scheme/normal'', ''light'', and ''dark'' are not valid <<custom-ident>>s in this property.
211177

212-
Repeating a keyword, such as ''color-scheme: light light'',
178+
Note: Repeating a keyword, such as ''color-scheme: light light'',
213179
is valid but has no additional effect
214180
beyond what the first instance of the keyword provides.
181+
</dl>
215182

216-
: <dfn lt=only>only</dfn>
217-
:: If provided,
218-
''only'' indicates that the element <em>must</em> be rendered with one of the specified [=color schemes=],
219-
if possible,
220-
even if the user's preference is for a different [=color scheme=].
221-
222-
Issue: Per spec, ''only'' can only be used with ''light''.
223-
Apple's implementation allows it with ''dark'' as well.
224-
The concern with ''only dark'' is that pages won't consider UAs that can't support ''dark'' schemes,
225-
and will thus render brokenly.
226-
This value might be expanded to all schemes or removed entirely
227-
depending on further consideration.
228-
229-
Authors <strong>should not</strong> use this value,
230-
and should instead ensure that their page renders well with whatever [=color scheme=] the user prefers
231-
(using the '@media/prefers-color-scheme' media query to adjust styles accordingly).
232-
This keyword is provided only for the rare cases where that might not be reasonably possible,
233-
and using a different color scheme would render the element difficult or impossible to use.
183+
<div class=example>
184+
A well-written page
185+
that responds to user preferences for light or dark display
186+
by using the 'prefers-color-scheme' media feature
187+
to alter the colors it uses
188+
can easily opt the browser-controlled UI
189+
(scrollbars, inputs, etc)
190+
into the user's preferred color scheme as well
191+
with a simple global declaration:
192+
193+
<pre highlight=css>
194+
:root {
195+
color-scheme: light dark;
196+
}
197+
</pre>
198+
</div>
234199

235-
Note: User agents are <strong>not required</strong>
236-
to support any particular [=color scheme=],
237-
so using ''only'' to indicate a required [=color scheme=]
238-
is still not guaranteed to have any effect on the rendering of the element.
239-
</dl>
200+
<div class=example>
201+
If a page limits itself to using <em>only</em> the <<system-color>>s,
202+
it can support the user's preferred color scheme
203+
without needing to use ''@media'' at all,
204+
simply by using the 'color-scheme' property:
205+
206+
<pre highlight=css>
207+
:root {
208+
color-scheme: light dark;
209+
}
210+
</pre>
240211

241-
Note: “Light” and “Dark” modes are not specific color palettes.
212+
because the [=used color scheme=]
213+
affects what <<system-color>>s resolve to.
214+
</div>
215+
216+
Note: “Light” and “dark” color schemes are not specific color palettes.
242217
For example,
243218
both a stark black-on-white scheme and a sepia dark-on-tan scheme
244219
would both be considered “Light” color schemes.
245220
To ensure particular foreground or background colors,
246221
they need to be specified explicitly.
247222

248-
Finding the Used Color Scheme {#color-scheme-processing}
249-
-----------------------------
250-
251-
<div algorithm>
252-
To find the <dfn>used color scheme</dfn> for an element |el|:
253-
254-
1. Let |scheme| be the keyword matching '@media/prefers-color-scheme'.
255-
256-
2. If the computed value of 'color-scheme' on |el|
257-
contains |scheme|,
258-
return |scheme|.
259-
260-
3. If the computed value of 'color-scheme' on |el| contains the ''only'' keyword
261-
or |scheme| is <css>no-preference</css>,
262-
and at least one [=color scheme=] indicated in 'color-scheme'
263-
is supported by the user agent,
264-
return the first keyword,
265-
in specified order,
266-
that is supported by the user agent.
267-
268-
4. Otherwise, return <css>no-preference</css>.
269-
</div>
223+
Note: Earlier versions of this property also defined an <css>only</css> keyword
224+
to be specified alongside a preferred color scheme,
225+
indicating a stronger author preference.
226+
It ended up being unnecessary,
227+
and was removed.
270228

271-
For each element,
272-
find the [=used color scheme=] for that element.
273-
If the [=used color scheme=] is <css>no-preference</css>,
274-
the element must be rendered with the user agent's default [=color scheme=].
275-
(For Web compatibility, this should be a “Light” [=color scheme=].)
276-
Otherwise,
277-
the element must be rendered with the [=used color scheme=].
278-
279-
Note: This algorithm ensures that
280-
if the user prefers a non-default [=color scheme=],
281-
it will only be used if the page claims to support it.
282-
This ensures that legacy pages,
283-
written before color scheme preferences were exposed,
284-
do not change behavior.
285229

286230
Effects of the Used Color Scheme {#color-scheme-effect}
287231
--------------------------------

0 commit comments

Comments
 (0)