Dark mode

The dark palette is turned on by the data-theme attribute on the root element.

<html data-theme="dark">

System theme

Pick the theme from the system setting and remember the user’s choice:

const saved = localStorage.getItem('theme');
const dark = saved
  ? saved === 'dark'
  : matchMedia('(prefers-color-scheme: dark)').matches;
document.documentElement.dataset.theme = dark ? 'dark' : 'light';

Page colour scheme

The library does not change the colour scheme of the rest of the page: color-scheme is set only together with the dark theme.