defineConfig({
  // ThemeSelect is rendered automatically in the header.
  // No additional configuration needed — dark, light, and auto
  // themes are available out of the box.
})
View Code

Overview

The ThemeSelect component renders a dropdown that lets users switch between dark, light, and auto (system preference) themes. It appears in the header and mobile menu footer.

Try it now — look for the theme toggle in the top-right corner of the header.

Props

PropTypeDefaultDescription
darkLabelstring"Dark"Label for the dark theme option
lightLabelstring"Light"Label for the light theme option
autoLabelstring"Auto"Label for the auto/system option
accessibleLabelstring"Select theme"Screen reader label for the dropdown
themeChanged(theme: string) => voidCallback fired when the user changes the theme

How It Works

  1. ThemeProvider renders a hidden <template> with SVG icons for sun, moon, and laptop
  2. ThemeSelect renders a Select dropdown with the three options
  3. On theme change, a callback updates the <html> element's data-theme attribute
  4. CSS custom properties respond to the data-theme value to swap colors

Theme Values

ValueDescription
lightForces light color scheme
darkForces dark color scheme
autoFollows the user's OS/browser preference via prefers-color-scheme
  • ThemeProvider — Renders the template icons used by ThemeSelect
  • Select — The underlying dropdown component that ThemeSelect wraps
  • MobileMenuFooter — Contains a ThemeSelect for mobile users

CSS Custom Properties

The theme system uses CSS layers and custom properties defined in design-tokens/props.css. Key properties that change with theme:

  • --sl-color-bg — Page background
  • --sl-color-text — Primary text color
  • --sl-color-text-accent — Accent/link color
  • --sl-color-bg-sidebar — Sidebar background
  • --sl-color-bg-nav — Header background