Skip to content

Dark Mode

The theme() mixin automatically inverts color palettes for dark mode.

@use "katanakit-js/scss/variables" as v;
@use "katanakit-js/scss/mixins" as m;
// Emits :root[data-theme="dark"] with inverted palettes
@include v.theme("dark");
// System preference hook
@include m.dark-mode {
:root {
color-scheme: dark;
}
}

The inversion formula is 800 - shade:

Light shade Dark shade
100 (lightest) 700 (darkest)
200 600
300 500
400 400
500 300
600 200
700 (darkest) 100 (lightest)
<html data-theme="dark">
<!-- Dark mode active -->
</html>
@include v.theme(
"dark",
(
"neutral": (
100: hsl(0, 0%, 12%),
700: hsl(0, 0%, 93%),
),
)
);