Skip to content

Commit 4eaed5c

Browse files
committed
docs for light-dark() function
1 parent 30b9d79 commit 4eaed5c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

website/pages/transpilation.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,63 @@ compiles to:
328328
}
329329
```
330330

331+
### light-dark() color function
332+
333+
The [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) function allows you to specify a light mode and dark mode color in a single declaration, without needing to write a separate media query rule. In addition, it uses the [`color-scheme`](https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme) property to control which theme to use, which allows you to set it programmatically. The `color-scheme` property also inherits so themes can be nested and the nearest ancestor color scheme applies.
334+
335+
Lightning CSS converts the `light-dark()` function to use CSS variable fallback when your browser targets don't support it natively. For this to work, you must set the `color-scheme` property on an ancestor element. The following example shows how you can support both operating system and programmatic overrides for the color scheme.
336+
337+
```css
338+
html {
339+
color-scheme: light dark;
340+
}
341+
342+
html[data-theme=light] {
343+
color-scheme: light;
344+
}
345+
346+
html[data-theme=dark] {
347+
color-scheme: dark;
348+
}
349+
350+
button {
351+
background: light-dark(#aaa, #444);
352+
}
353+
```
354+
355+
compiles to:
356+
357+
```css
358+
html {
359+
--lightningcss-light: initial;
360+
--lightningcss-dark: ;
361+
color-scheme: light dark;
362+
}
363+
364+
@media (prefers-color-scheme: dark) {
365+
html {
366+
--lightningcss-light: ;
367+
--lightningcss-dark: initial;
368+
}
369+
}
370+
371+
html[data-theme="light"] {
372+
--lightningcss-light: initial;
373+
--lightningcss-dark: ;
374+
color-scheme: light;
375+
}
376+
377+
html[data-theme="dark"] {
378+
--lightningcss-light: ;
379+
--lightningcss-dark: initial;
380+
color-scheme: dark;
381+
}
382+
383+
button {
384+
background: var(--lightningcss-light, #aaa) var(--lightningcss-dark, #444);
385+
}
386+
```
387+
331388
### Logical properties
332389

333390
CSS [logical properties](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties) allow you to define values in terms of writing direction, so that UIs mirror in right-to-left languages. Lightning CSS will compile these to use the `:dir()` selector when unsupported. If the `:dir()` selector is unsupported, it is compiled as described [below](#%3Adir()-selector).

0 commit comments

Comments
 (0)