UIGetting startedReact
Theming
Every color and the corner radius is a CSS variable with the name shadcn/ui gives it. Change a value and every component follows.
How tokens pair
Most tokens come in twos: a surface such as --primary and the color of text and icons on it, --primary-foreground. A component that paints bg-primary writes its label in text-primary-foreground, so a theme only has to keep each pair readable. A few tokens stand alone: --border, --input and --ring (the focus outline), the five chart colors, and --radius.
The values live in two blocks of your stylesheet: :root holds the light ones and .dark the dark ones (Dark mode). The components never name a color; they name a token.
Tokens
The theme maps each token to a Tailwind CSS color with @theme inline, so --color-primary gives bg-primary, text-primary, border-primary and the rest. This table is read from that mapping in packages/ui/tokens/base.css, with the neutral theme's values:
| Token | Tailwind CSS | Light | Dark |
|---|---|---|---|
--background | --color-background | oklch(1 0 0) | oklch(0.145 0 0) |
--foreground | --color-foreground | oklch(0.145 0 0) | oklch(0.985 0 0) |
--card | --color-card | oklch(1 0 0) | oklch(0.205 0 0) |
--card-foreground | --color-card-foreground | oklch(0.145 0 0) | oklch(0.985 0 0) |
--popover | --color-popover | oklch(1 0 0) | oklch(0.205 0 0) |
--popover-foreground | --color-popover-foreground | oklch(0.145 0 0) | oklch(0.985 0 0) |
--primary | --color-primary | oklch(0.205 0 0) | oklch(0.922 0 0) |
--primary-foreground | --color-primary-foreground | oklch(0.985 0 0) | oklch(0.205 0 0) |
--secondary | --color-secondary | oklch(0.97 0 0) | oklch(0.269 0 0) |
--secondary-foreground | --color-secondary-foreground | oklch(0.205 0 0) | oklch(0.985 0 0) |
--muted | --color-muted | oklch(0.97 0 0) | oklch(0.269 0 0) |
--muted-foreground | --color-muted-foreground | oklch(0.556 0 0) | oklch(0.708 0 0) |
--accent | --color-accent | oklch(0.97 0 0) | oklch(0.269 0 0) |
--accent-foreground | --color-accent-foreground | oklch(0.205 0 0) | oklch(0.985 0 0) |
--destructive | --color-destructive | oklch(0.577 0.245 27.325) | oklch(0.704 0.191 22.216) |
--border | --color-border | oklch(0.922 0 0) | oklch(1 0 0 / 10%) |
--input | --color-input | oklch(0.922 0 0) | oklch(1 0 0 / 15%) |
--ring | --color-ring | oklch(0.708 0 0) | oklch(0.556 0 0) |
--chart-1 | --color-chart-1 | oklch(0.87 0 0) | oklch(0.87 0 0) |
--chart-2 | --color-chart-2 | oklch(0.556 0 0) | oklch(0.556 0 0) |
--chart-3 | --color-chart-3 | oklch(0.439 0 0) | oklch(0.439 0 0) |
--chart-4 | --color-chart-4 | oklch(0.371 0 0) | oklch(0.371 0 0) |
--chart-5 | --color-chart-5 | oklch(0.269 0 0) | oklch(0.269 0 0) |
--sidebar | --color-sidebar | oklch(0.985 0 0) | oklch(0.205 0 0) |
--sidebar-foreground | --color-sidebar-foreground | oklch(0.145 0 0) | oklch(0.985 0 0) |
--sidebar-primary | --color-sidebar-primary | oklch(0.205 0 0) | oklch(0.488 0.243 264.376) |
--sidebar-primary-foreground | --color-sidebar-primary-foreground | oklch(0.985 0 0) | oklch(0.985 0 0) |
--sidebar-accent | --color-sidebar-accent | oklch(0.97 0 0) | oklch(0.269 0 0) |
--sidebar-accent-foreground | --color-sidebar-accent-foreground | oklch(0.205 0 0) | oklch(0.985 0 0) |
--sidebar-border | --color-sidebar-border | oklch(0.922 0 0) | oklch(1 0 0 / 10%) |
--sidebar-ring | --color-sidebar-ring | oklch(0.708 0 0) | oklch(0.556 0 0) |
--radius | --radius-* | 0.625rem | · |
A dot in the Dark column means the token keeps its light value in dark mode.
Radius
One value, --radius, sets every corner. The rounded utilities are steps of it, so a rounder or squarer theme changes one line:
| Utility | Value |
|---|---|
rounded-sm | calc(var(--radius) * 0.6) |
rounded-md | calc(var(--radius) * 0.8) |
rounded-lg | var(--radius) |
rounded-xl | calc(var(--radius) * 1.4) |
rounded-2xl | calc(var(--radius) * 1.8) |
rounded-3xl | calc(var(--radius) * 2.2) |
rounded-4xl | calc(var(--radius) * 2.6) |
Install the theme
An app that ran shadcn init already has these names and keeps its own values. Any other app adds the theme item, which writes the tokens, the @theme inline mapping and the base styles into its stylesheet:
npx shadcn@4.23.0 add https://hamur.dev/r/react/theme-neutral.jsonAdd a token
Give the token a value in both modes, then map it in @theme inline. Tailwind CSS then has bg-warning and text-warning-foreground:
:root {
--warning: oklch(0.84 0.16 84);
--warning-foreground: oklch(0.28 0.07 46);
}
.dark {
--warning: oklch(0.41 0.11 46);
--warning-foreground: oklch(0.99 0.02 95);
}
@theme inline {
--color-warning: var(--warning);
--color-warning-foreground: var(--warning-foreground);
}