oakoss/ui
Theming

Token Names

How color token names are built, and how each role gets its color when a theme family is made.

A color token is named for its role, not its color: --primary, not --blue-600. Changing the family or primary color changes the values, and every name stays the same. The Color Tokens page lists every token with its value.

Neutral roles

Neutral roles keep shadcn's names, so code written for shadcn reads the same tokens. A surface and the text on it share a stem:

  • --card is the surface, and --card-foreground is text on it.
  • --sidebar-* repeats the set for the sidebar.
  • --border is for dividers and decoration, with no contrast minimum. --input is the border of a form control, held to 3:1.
  • --field is the background of a form control, set by the style rather than the family.

Each family maps its neutral roles by hand to palette colors, such as zinc-950 or white at 10% opacity. Zinc's map:

TokenDescriptionZinc lightZinc dark
--backgroundThe page background.whitezinc-950
--foregroundDefault text on background.zinc-950zinc-50
--cardCard surface.whitezinc-900
--card-foregroundText on card.zinc-950zinc-50
--popoverPopover, menu and dialog surface.whitezinc-900
--popover-foregroundText on popover.zinc-950zinc-50
--secondaryNeutral fill for secondary actions. Stays neutral whichever primary is chosen.zinc-100zinc-800
--secondary-foregroundText on secondary.zinc-900zinc-50
--mutedMuted surface for secondary content.zinc-100zinc-800
--muted-foregroundSecondary text, on muted or background.zinc-600zinc-400
--accentSubtle surface for hovered and highlighted items. Menu item hover, selected list row.zinc-100zinc-800
--accent-foregroundText on accent.zinc-900zinc-50
--borderDividers and decorative outlines. Not for the sole boundary of an interactive control.zinc-200white / 10%
--inputBorder of form controls.zinc-500zinc-500
--sidebarSidebar surface.zinc-50zinc-900
--sidebar-foregroundText on sidebar.zinc-950zinc-50
--sidebar-accentHovered item in the sidebar.zinc-100zinc-800
--sidebar-accent-foregroundText on sidebar-accent.zinc-900zinc-50
--sidebar-borderDividers inside the sidebar.zinc-200white / 10%
--fieldBackground of form controls, set by the style.transparent--foreground / 4.5%

Intent roles

Each of the five intents, primary, destructive, success, warning and info, gets the same set of roles. The bare intent name is the solid fill, and a suffix names the rest:

TokenDescriptionStep
--{intent}Solid fill, such as a button background.The step nearest the scale's anchor whose foreground passes 4.5:1 and which passes 3:1 on the page
--{intent}-hoverThe solid fill when hovered or pressed.The fill's neighbor away from the foreground, else its other neighbor: the first that passes 4.5:1 with the foreground
--{intent}-subtleSoft tinted background.50 in light, 950 in dark
--{intent}-borderTinted outline, for soft badges and alerts. Decorative; not a control boundary.200 in light, 800 in dark
--{intent}-textIntent-colored text on the page. Links, outline buttons, soft badges.From 600 in light, 400 in dark, the first step away from the page that passes 4.5:1 on the page and on subtle, pressed too
--{intent}-foregroundText and icons on the solid fill.Step 50 or 950, whichever contrasts more with the fill

The family chooses each intent's color, and you can change the primary. The steps aren't fixed: the generator picks them for each color and flavor by contrast, so --primary isn't the same step in every scale or flavor.

Scales

Each intent also exposes its whole scale, --primary-50 to --primary-950, for the rare color no role covers. Prefer a role: a step keeps its value when the flavor changes, so text on it can fail contrast in dark mode.

Derived roles

shadcn names a few roles that follow another token rather than a palette color:

TokenFollowsDescription
--ring--primary-textFocus ring. Follows primary-text, which passes 3:1 on the page, cards and popovers.
--sidebar-primary--primaryPrimary fill inside the sidebar.
--sidebar-primary-foreground--primary-foregroundText on sidebar-primary.
--sidebar-ring--primary-textFocus ring inside the sidebar.

Focus rings follow --primary-text rather than --primary: the fill only has to pass 3:1 on the page, and fails it on dark cards and popovers.

Charts

--chart-1 to --chart-5 color data series. Every family reads five steps of the primary color's scale; Zinc's:

TokenDescriptionZinc's color
--chart-1First chart series. Data series; a family chooses a ramp or categorical hues.Step 300 of the primary scale
--chart-2Second chart series. Data series; a family chooses a ramp or categorical hues.Step 500 of the primary scale
--chart-3Third chart series. Data series; a family chooses a ramp or categorical hues.Step 600 of the primary scale
--chart-4Fourth chart series. Data series; a family chooses a ramp or categorical hues.Step 700 of the primary scale
--chart-5Fifth chart series. Data series; a family chooses a ramp or categorical hues.Step 800 of the primary scale

Contrast

Every family, flavor and primary color passes these pairs, which the token package checks in its tests. Decorative pairs, such as --border on the page, have no minimum.

TextBackgroundMinimum
--foreground--background4.5:1
--card-foreground--card4.5:1
--popover-foreground--popover4.5:1
--secondary-foreground--secondary4.5:1
--muted-foreground--muted4.5:1
--muted-foreground--background4.5:1
--accent-foreground--accent4.5:1
--sidebar-foreground--sidebar4.5:1
--sidebar-accent-foreground--sidebar-accent4.5:1
--primary-foreground--primary4.5:1
--primary-foreground--primary-hover4.5:1
--primary-text--background4.5:1
--primary-text--primary-subtle4.5:1
--primary--background3:1
--destructive-foreground--destructive4.5:1
--destructive-foreground--destructive-hover4.5:1
--destructive-text--background4.5:1
--destructive-text--destructive-subtle4.5:1
--destructive--background3:1
--success-foreground--success4.5:1
--success-foreground--success-hover4.5:1
--success-text--background4.5:1
--success-text--success-subtle4.5:1
--success--background3:1
--warning-foreground--warning4.5:1
--warning-foreground--warning-hover4.5:1
--warning-text--background4.5:1
--warning-text--warning-subtle4.5:1
--warning--background3:1
--info-foreground--info4.5:1
--info-foreground--info-hover4.5:1
--info-text--background4.5:1
--info-text--info-subtle4.5:1
--info--background3:1
--ring--background3:1
--ring--card3:1
--ring--popover3:1
--sidebar-ring--sidebar3:1
--input--background3:1
--destructive-text--background3:1
--input--card3:1
--destructive-text--card3:1
--input--popover3:1
--destructive-text--popover3:1