css-light-dark
Installation
SKILL.md
CSS Light and Dark
-
Make the tokens
light-dark(<light>, <dark>)pairs on:rootwithcolor-scheme: light dark, so the site follows the system. Acolor-schemeset on the root element forces one scheme, which is how the Storybook toolbar switches it:/* uikit/variables.css */ :root { --colorBackground: light-dark(#f2f2f4, #1d1d1f); --colorText: light-dark(#1d1d1f, #ececee); /* light-dark() takes colors alone: a shadow gets one for each of its colors */ --shadowCard: 0 1px 2px light-dark(rgb(0 0 0 / 12%), rgb(0 0 0 / 40%)); /* ... */ color-scheme: light dark; } -
Don't put tokens behind
@media (prefers-color-scheme: dark): they follow the system and nothing else, and no forced scheme reaches them. -
Keep
light-dark()native in the built CSS: lightningcss compiles it for older targets into variables switched byprefers-color-scheme, which a forcedcolor-schemecan't reach. Exclude the feature from its transforms: