nook
Browse the docs

Theming

Every Nook component reads CSS variables. There is no color written inside a component, so changing the variables changes everything, in light and dark mode.

Make a theme

The fastest way is the customizer. Pick a style, brand color, radius, font and density. Nook builds a full palette from your color and checks that text stays readable. Then apply it:

npx nook-ui@latest add theme cobalt        # a preset
npx nook-ui@latest add theme nk1_eyJi...   # a code copied from the customizer

You can also press Copy CSS in the customizer and paste it into your stylesheet. The CSS is byte for byte what add theme writes, because both come from the same function.

Tokens

TokenUsed for
background, foregroundThe page and its text
card, popover (+ -foreground)Raised surfaces
primary (+ -foreground)Main actions. Ink in the sharp style, the brand color in soft and bold
brand (+ -foreground)Checked controls and other small brand-colored surfaces
secondary (+ -foreground)Quiet actions
muted (+ -foreground)Subtle backgrounds and helper text
accent (+ -foreground)Hover and selected states
destructive (+ -foreground)Dangerous actions and errors
border, input, ringLines, control borders and focus rings
radiusBase corner radius. rounded-sm to rounded-xl scale from it
font-bodyThe font family
densityA multiplier for control sizes: compact 0.875, comfortable 1, spacious 1.125
elevation-1 to elevation-3Shadows (shadow-sm, shadow-md, shadow-lg)
edgeBorder width of the style: 1px, or 2px in bold
pressThe transform a control takes while pressed
motion-fast, motion-pop, motion-ease, motion-ease-popDurations and easings of the style

Styles

A style sets the character of every component: how it is edged, lit and how it moves. It is part of the theme, so switching style never touches component code.

StyleLooks like
sharp (default)Thin lines, ink buttons, the brand color as a small accent, quick motion
softRaised surfaces, brand-colored buttons, a gentle bounce
boldThick outlines, hard shadows, loud color
npx nook-ui@latest init --style soft   # start a project in a style
npx nook-ui@latest add theme poster    # or switch later with a preset or code

How colors are made

From one brand color, Nook builds a 50 to 950 scale in the OKLCH color space. OKLCH keeps lightness even between hues, so a yellow 500 and a blue 500 feel equally strong.

The semantic tokens pick from that scale and from a neutral scale that carries a hint of the brand hue. Then Nook measures contrast with the WCAG formula:

  • Text pairs need 4.5:1.
  • Input borders and focus rings need 3:1 against the page.

If your brand color cannot carry button text, Nook moves to the nearest step that can and tells you in the customizer.

Density-aware sizes

Tailwind utilities h-control-sm, h-control, h-control-lg, px-inset-sm, px-inset and px-inset-lg follow the density token. Use them in your own components to match.

Dark mode

Add the dark class to an ancestor, usually <html>. The generated CSS contains both schemes.

Using only the theme

Run init and skip add. You keep the tokens and the Tailwind utilities, and no component code.