Theming
The tokens every component is styled with, and how dark mode switches them.
The theme sets shadcn's standard color variables, so other shadcn components match. It lives in your CSS, and changing a token there changes every component that uses it.
Dark mode
Every token has a dark value, which applies inside any element with the dark class. Tailwind's
dark: variant applies there too. The theme also sets color-scheme: dark on that element, so
scrollbars and native form controls follow.
Put the class on <html> to switch the whole page. The class has to be there before the page first
paints, or a dark page flashes light while it loads. To prevent that, a script at the top of
<head> sets the class from the person's stored choice, or from the system setting until they make
one. A provider then stores each new choice. While the choice is System, the provider follows the
system setting as it changes.
Below are setups for Next.js and Vite. For other frameworks, such as Astro, Remix and TanStack Start, follow shadcn's dark mode guides, which set the same class.
Next.js
next-themes provides both the script and the provider. Install it.
Wrap the root layout in its ThemeProvider, and add suppressHydrationWarning to <html>,
since the next-themes script changes the class before React hydrates.
disableTransitionOnChange turns transitions off for the moment the theme switches, so controls
change color at once rather than fading one by one.
Vite
Add the script to <head> in index.html, before anything that renders. It falls back to the
system setting when nothing valid is stored, and leaves the page alone if storage is blocked.
Then add a provider, and wrap the app in it.
The provider stores the choice under the theme key, the same key next-themes uses.
Toggle
A Dropdown Menu with a radio item for each choice lets people pick a
theme and shows which one is set. The trigger's icon switches with the dark: variant, so it shows
the right icon even before the provider knows the choice. Import useTheme from next-themes in
Next.js, or from @/components/theme-provider with the Vite provider. Both return the theme and
setTheme that the toggle uses.
Tokens
Alongside shadcn's variables, the theme adds these.
The page paints background, and fields, tables and code blocks paint layer-0, so the page can
sit further back than anything on it. Cards paint card. Popovers, menus, tooltips, dialogs and
sheets paint popover.
surface is the page's background until a Card, popup or dialog sets it to
its own color. Parts that blend into whatever holds them, such as Sticky Header's bar or
Grid's solid cells, paint surface so they match.
shadcn's accent, input, muted and sidebar-* variables are kept so components from elsewhere
keep working, but nothing in Jarvis UI uses them.
Colors
Each color token is shown in light and dark mode. Values such as grey-50 are steps of the
palette. Hover a swatch to see the color it resolves to.
Surfaces
Text and icons
Borders
Controls
Overlays
Overlays are translucent. primary-hover and primary-pressed are shown over primary.
States
Syntax
The syntax tokens color code, such as the keys and values in JSON Viewer,
with steps from the palette. The code blocks on this site use them too, with faint for comments
and muted-foreground for punctuation. A JSX component's name is colored syntax-function, the
same as its import, and syntax-tag colors HTML elements.
Charts
Sidebar
Palette
Palette steps are the same in both modes. The theme inlines each step's value into the tokens that
use it, so an installed project has the tokens but no --palette-* variables. Pick a value from
here to re-theme a token.
Type scale
text-base stays at 16px, so inputs can use text-sm any-pointer-coarse:text-base to keep iOS
from zooming in on touch screens of any width.