On this page

Dark mode

Dark mode is easier on the eyes in low light. Name each colour token once and it works in both themes.

Many people switch to dark mode at night, and some prefer it all day. Supporting it costs nothing extra: write each token once; the theme changes the value.

Connections Add connection
Online storeSynced 2 min ago Synced
ERPToken expires in 3 daysExpiring
AccountingView error log Failed
Light
Connections Add connection
Online storeSynced 2 min ago Synced
ERPToken expires in 3 daysExpiring
AccountingView error log Failed
Dark: the same tokens, no extra code

How it works

Every colour token has a light and a dark value under the same name. The theme picks the value; your code and designs name the token once. The dark values of every palette step are on Palette, and every role token’s are on Tokens.

Turn it on in code

Follow the reader’s system setting, let them change it, and remember their choice.

The token CSS (@beehexa/design-tokens/css) already holds both themes. It picks the dark values in two cases:

Case What decides the theme
data-theme="dark" on <html> Your product: the reader chose dark
No data-theme, and the system is dark The reader’s system setting (prefers-color-scheme: dark)

data-theme="light" keeps the light values even when the system is dark.

Set the theme before the page draws, in a small script in <head>, so the page doesn’t flash light first:

<script>
  let theme = localStorage.getItem('bh-theme');
  if (theme !== 'light' && theme !== 'dark') {
    theme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
  }
  document.documentElement.dataset.theme = theme;
</script>
  • Set color-scheme to match (color-scheme: dark under [data-theme='dark']), so scrollbars, form controls and the browser’s own UI follow the theme.
  • Put the theme switch in the header. Save the choice only when the reader picks one; until then, follow the system.
  • A part that must keep one theme whatever the page uses, such as a fixed preview, takes the class bh-scope-light or bh-scope-dark.
  • Charts, code editors and anything else that needs colour values instead of CSS variables must redraw when the theme changes.

Surfaces and shadows

In light, shadows separate the levels. In dark, the background gets lighter as the surface rises, and the shadow gets stronger.

Level Light Dark
Page (color.surface.page) White Graphite 1, the darkest
Card (color.surface), elevation.shadow.raised White, faint graphite shadow Graphite 2, black shadow at 40% and 30%
Menu, popover, dialog (color.surface.overlay), elevation.shadow.overlay and .modal White, graphite shadow at 15% Graphite 3, black shadow at 50%

Dark mode adds no border to show a level. Rows in menus and popovers use the overlay state colours, such as color.surface.overlay.hover. See Elevation.

Colours that change more

  • The primary button turns light with dark text. That is intended, not a reason to make it blue.
  • Solid status fills get brighter, with dark text on them (color.text.on-bold).
  • Hover and pressed fills get lighter instead of darker. The state tokens already do this; see Interaction states.

Images and logos

  • Logos use their dark-background versions: the wordmark turns white, the yellow mark stays. See Logos.
  • Give screenshots and illustrations a version for each theme. If an image has only a light version, put it on a light frame (bh-scope-light) instead of on the dark page.
  • Don’t invert images or change them with CSS filters. Colours shift and brand colours break.
  • An image of something turned off fades the same way in both themes (opacity.disabled); see Opacity.

Check before release

  • Every screen in both themes, including empty, loading and error states.
  • No colour written by hand and none picked by theme in code. Every colour is a token.
  • Text, icons and borders pass contrast in both themes. The token pairs are checked already; check anything you place on an image.
  • The focus ring is visible on every surface.
  • Menus, popovers and dialogs stand out from the card under them.
  • Charts read in both themes, and no series disappears into the background.
  • Logos, screenshots and illustrations have their dark versions or sit on a light frame.
  • Scrollbars and form controls follow the theme (color-scheme).
  • The theme switch works with the keyboard, and the choice is remembered after reload.