elements
Start Docs Blog Demos UI Pricing
Elements Manual
  • Getting Started
  • CLI
  • Build
  • Browser
  • Packages
  • TypeScript
  • Elements HTML
  • Assets
  • RPC
  • Router
  • Session
  • Database
  • Migrations
  • LiveTable
  • Channel
  • Jobs
  • Email
  • Payments
  • JSON
  • Async
  • Style
    • Install
    • Tokens
    • Base elements
    • Typography
    • Layout
    • Components
    • Utilities
    • Theming
      • Branding
      • Dark mode
    • Overriding
    • Email
    • Reference
  • UI
  • JSOC
  • Config
  • Tests
  • Logs
  • Deploy
  • Editors
  • Recipes
  • Licenses
  • Issues
  • Changelog
Manual / Style/ Theming/ Dark mode

Dark mode

elements man style/theming/dark-mode

On This Page

  • How dark mode remaps the tokens
  • OS preference by default
  • Forcing a mode with data-theme
  • Writing dark-ready CSS
  • Exception: email
  • color-scheme

Dark mode is built into the default theme. You don't build a second stylesheet or add dark: variants to your markup. The default theme gives each semantic token a second value for dark mode, and every rule that reads a semantic token uses that value.

How dark mode remaps the tokens

themes/default.css defines the light semantic tokens on :root, then remaps the same tokens for dark mode. The ramp values stay the same; each semantic token is set to a different ramp step. --bg goes from white to --neutral-950, --ink from --neutral-900 to --neutral-50, and so on for every surface, ink, rule, accent, and status token.

Because components never check the mode (they only read semantic tokens), anything you build from tokens is dark-ready with no extra work. A card that uses var(--bg) and var(--ink) is correct in both modes with no extra rules.

OS preference by default

By default the app follows the operating system's preference through @media (prefers-color-scheme: dark). A user whose OS is in dark mode sees your app in dark mode with no configuration.

Forcing a mode with data-theme

To let users override the OS preference, set a data-theme attribute on <html>:

  • data-theme="dark" forces dark mode.
  • data-theme="light" forces light mode (it also suppresses the OS dark preference).

The attribute overrides the OS setting: the dark media query skips [data-theme="light"], and [data-theme="dark"] applies the dark tokens. Wire it to a user toggle (whatever JavaScript your app uses to flip the attribute) and persist the choice. The dark token set is defined twice in themes/default.css (once in the media query, once under the attribute) and the two blocks are kept identical.

Theme attribute
<!-- OS preference --> <html> <!-- force dark regardless of OS --> <html data-theme="dark"> <!-- force light regardless of OS --> <html data-theme="light">

Writing dark-ready CSS

Consume semantic tokens and you never write a dark-mode rule:

Semantic tokens
/* Correct in both modes automatically */ .panel { background: var(--bg-panel); color: var(--ink); border: 1px solid var(--rule); }

A raw ramp step (--neutral-50) has the same value in both modes, so a rule that uses one stays light in dark mode. Use --bg*, --ink*, --rule*, --accent*, and the status tokens.

Exception: email

The email baseline is exempt. Mail clients can't reliably resolve CSS variables, so email.css ships raw values and is light-only. See email (opens in a new tab).

color-scheme

The theme also sets the CSS color-scheme property (light on :root, dark in the dark blocks), so native form controls, scrollbars, and the browser chrome match the active mode.

Prev BrandingNext Overriding
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026