css-light-dark

Installation
SKILL.md

CSS Light and Dark

  • Make the tokens light-dark(<light>, <dark>) pairs on :root with color-scheme: light dark, so the site follows the system. A color-scheme set 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 by prefers-color-scheme, which a forced color-scheme can't reach. Exclude the feature from its transforms:

Installs
1
First Seen
13 days ago