Theming
NightCSS is themed entirely through custom properties. The theme follows the
operating system by default, can be forced with data-theme, and any token can be
overridden in the runtime.
Automatic light and dark
Section titled “Automatic light and dark”The color tokens are written with light-dark() and :root sets
color-scheme: light dark, so the page follows the OS preference with no extra
markup:
--nc-surface: light-dark(oklch(100% 0 0), oklch(19% 0 0));The light value is used when the OS is light, the dark value when it is dark.
Force a theme
Section titled “Force a theme”Set a data-theme attribute on <html> and import the matching override:
<html data-theme="dark">@import "nightcss/themes/dark";The override sets color-scheme, which flips every light-dark() token. The
light and dark files are exported as nightcss/themes/light and
nightcss/themes/dark.
Override any token
Section titled “Override any token”Re-theme at runtime by overriding tokens on :root (or any element). Overrides
cascade and are scoped like any custom property:
:root { --nc-accent: oklch(45% 0.2 280); --nc-radius-md: 0.75rem; --nc-space-4: 1.25rem;}Because the tokens are plain custom properties, a single override re-themes every utility and component that reads it.
The escape hatch
Section titled “The escape hatch”Every scale utility reads a short custom property with a token fallback, so arbitrary values work inline, with no build step:
<div class="p-4" style="--p: 37px">…</div><div class="w-4" style="--w: 12rem">…</div>| Family | Variable |
|---|---|
Padding (p-*, px-*, py-*) |
--p |
Margin (m-*, mx-*, my-*) |
--m |
Gap (gap-*) |
--gap |
Vertical rhythm (space-y-*) |
--space-y |
Width / height (w-*, h-*) |
--w, --h |
Border radius (rounded-*) |
--radius |
Font size (text-*) |
--text-size |
Box shadow (shadow-*) |
--shadow |
The min-w-*, max-w-*, and min-h-* families are fixed presets, not
variable-backed. For an arbitrary min/max dimension, write min-inline-size,
max-inline-size, or min-block-size in your own CSS.
See Utilities for the full list of utility families.