@@ -222,36 +222,80 @@ Opting Into a Preferred Color Scheme: the 'color-scheme' property {#color-scheme
222
222
is still not guaranteed to have any effect on the rendering of the element.
223
223
224
224
<div class=example>
225
- A well-written page--
226
- one that responds to user preferences for light or dark display
225
+ A page that responds to user preferences for light or dark display
227
226
by using the 'prefers-color-scheme' media feature
228
- to alter the colors it uses--
227
+ to alter the colors it uses
229
228
can easily opt the browser-controlled UI
230
229
(scrollbars, inputs, etc)
231
- into the user's preferred color scheme as well
230
+ to match
232
231
with a simple global declaration:
233
232
234
233
<pre highlight=css>
235
234
:root {
236
235
color-scheme: light dark;
237
236
}
238
237
</pre>
238
+
239
+ If a page limits itself to using <em> only</em> the <<system-color>> s,
240
+ the 'color-scheme' declaration, above,
241
+ will support the user's preferred color scheme
242
+ even without the author needing to use ''@media'' at all.
239
243
</div>
240
244
241
245
<div class=example>
242
- If a page limits itself to using <em> only</em> the <<system-color>> s,
243
- it can support the user's preferred color scheme
244
- without needing to use ''@media'' at all,
245
- simply by using the 'color-scheme' property:
246
+ If a page cannot reasonably accommodate all color schemes,
247
+ such as for branding or theatrical reasons,
248
+ 'color-scheme' can still indicate which color schemes the page <em> can</em> support,
249
+ causing the UI to match.
250
+
251
+ If the page's color scheme is primarily light,
252
+ the following will indicate that explicitly:
253
+
254
+ <pre highlight=css>
255
+ :root {
256
+ color-scheme: light;
257
+ }
258
+ </pre>
259
+
260
+ While if the page is primarily dark,
261
+ indicating that explicitly will make the page look more coherent as well:
262
+
263
+ <pre highlight=css>
264
+ :root {
265
+ color-scheme: dark;
266
+ }
267
+ </pre>
268
+
269
+ However, it is better to support both color schemes,
270
+ of course.
271
+ </div>
272
+
273
+ <div class=example>
274
+ A page might be generally capable of handling multiple color schemes,
275
+ while still having a sub-section that needs to be rendered in a particular color scheme.
276
+
277
+ For example,
278
+ a style guide might give several UI examples that are using light or dark colors,
279
+ showing off the light or dark theme specifically.
280
+ This can be indicated as:
246
281
247
282
<pre highlight=css>
248
283
:root {
249
284
color-scheme: light dark;
250
285
}
286
+
287
+ .light-theme-example {
288
+ color-scheme: light;
289
+ }
290
+
291
+ .dark-theme-example {
292
+ color-scheme: dark;
293
+ }
251
294
</pre>
252
295
253
- because the [=used color scheme=]
254
- affects what <<system-color>> s resolve to.
296
+ Only the subsections rooted at ''.light-theme-example'' or ''.dark-theme-example''
297
+ will be opted into the ''light'' or ''dark'' themes specifically;
298
+ the rest of the page will respect the user's preference.
255
299
</div>
256
300
257
301
Note: [[HTML]] specifies a
0 commit comments