Overview
A token is a CSS custom property that NDS defines at :root, in four tiers. Semantic tokens read the palette. Component tokens read a semantic or a palette token. A change low in the chain reaches every token that reads it.
- Palette: the raw colors, such as
--colors-primary-600. A theme replaces the four brand ramps. Base, the alphas and the status hues stay fixed. - Primitives: the sizes, such as
--spacing-xl: spacing, radius, typography, the font, the page shell and the transition. - Semantic: one meaning each, system-wide, such as
--text-error. The value is a palette token. - Component: one component’s own dial, such as
--button-background-primary-default. The value is a semantic or palette token.
Pick another page when:
- you change the brand colors of the whole site: Themes
- you restyle one component: the Tokens table in that component’s API
- you style one element of a component: the CSS Custom Properties table in that component’s API
Markup
Variants
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Pack | Brand colors (default) (hint: Palette tokens) | — | — | The four brand ramps, which a theme replaces. Read them through a semantic token when one has the meaning |
| Pack | Fixed colors (hint: Palette tokens) | canon #tokens-fixed |
— | Black, white, the white and black alphas, and the status ramps. A theme does not change them |
| Pack | Spacing (hint: Primitive tokens) | canon #tokens-spacing |
— | Gaps, padding and margins, on a 4px grid |
| Pack | Radius (hint: Primitive tokens) | canon #tokens-radius |
— | Corner radius |
| Pack | Typography (hint: Primitive tokens) | canon #tokens-typography |
— | The fixed sizes: font size (-FS) and line height (-LH). Use each FS with its LH |
| Pack | Fluid typography (hint: Primitive tokens) | canon #tokens-fluid |
— | The sizes that grow with the screen width, between a minimum and a maximum. The display sizes add the space below (-MB) |
| Pack | Font (hint: Primitive tokens) | canon #tokens-font |
— | The font family and the four font weights |
| Pack | Shadow (hint: Semantic tokens) | canon #tokens-shadow |
— | Shadows from xs to 3xl, a top shadow and an inset shadow |
| Pack | Layout & shell (hint: Primitive tokens) | canon #tokens-shell |
— | The page shell sizes, the content width and the transition |
| Pack | Background (hint: Semantic tokens) | canon #tokens-background |
— | Surface colors by meaning: page, card, menu, overlay, brand and status fills |
| Pack | Text (hint: Semantic tokens) | canon #tokens-text |
— | Text colors by meaning: body, display, brand, status, on a colored fill, disabled |
| Pack | Border & focus (hint: Semantic tokens) | canon #tokens-border |
— | Border colors by meaning, the divider and the focus ring |
| Pack | Icon (hint: Semantic tokens) | canon #tokens-icon |
— | Icon colors by meaning, with their light fills and rings |
| Pack | Controls (hint: Semantic tokens) | canon #tokens-controls |
— | The fills that checkbox, radio, switch and slider share |
| Pack | Component (hint: Component tokens) | canon #tokens-component |
— | Each component’s own tokens, under its name. Set them to restyle that component alone. Each component’s page lists its own |
Behavior
Knobs
A knob styles one element, such as --btn-size. It is undefined by default, and the component falls back to its own value. Set it in the element’s style or on a class. A knob set on a wrapper reaches every component inside.
Resolution Chain
A painted value goes down a chain from a knob to the palette. Change any token in the chain, and everything above it follows.
Dark Mode
data-theme="dark" on <html> switches the semantic and component tokens to their dark values. On any other element, it makes that element a dark area: both tiers are declared again on it, with dark values. Some components also have dark rules of their own. Switching and saving the mode is on the Themes page.
Override Scope
A token that reads another token takes its value where it is declared. The semantic and component tokens are declared at :root, so they read the palette there. A palette token set on a wrapper does not change them. On a wrapper, set the token that the component reads.
To change a token on every page, set it in your own stylesheet, loaded after nds-main.min.css. Repeat both NDS selectors: a dark area declares every token again with the NDS values, so a plain :root rule does not reach it. Give the override a dark value too, or dark mode shows the NDS one. A pack’s code has both rules: copy it and keep only the lines you change.
Built-in Features
-
Fluid Typography
The
--typo-display-clamp-*and--typo-text-clamp-*sizes grow with the screen width, between a minimum and a maximum. -
Font Sizing
Every font size and line height multiplies by
--user-font-scale, which the Accessibility panel sets on<html>. It works there only: the tokens resolve on the root. -
Phone Padding
--nds-viewport-paddingis 32px, and half of that below 600px. Menus and tooltips keep the same space from the sides of the screen, so they line up with the page content. -
Weights per Theme
The themes with a font of their own, Cairo or Readex Pro, set the
--font-weight-*tokens one step lower: 300 to 600.
Best Practices
- Use an NDS component before you style an element of your own. Tokens are for the CSS you write.
- Write
var(--token)for every color, size and shadow. Never write a hex value or a pixel size that a token names. - In your own CSS, pick a semantic token by its meaning. Do not read a component token because its value matches today: it can change with that component.
- Use a palette token only when no semantic token has the meaning. Take every state of a family from the same tier.
- Pair each font size with its line height:
--typo-text-md-FSwith--typo-text-md-LH. - To restyle one component in one place, set its component tokens on a wrapper. Set every state of the family, or the hover color stays the old one.
- Set palette tokens at
:rootonly. On a wrapper, they do not reach the tokens that read them. - To change the brand colors, use a theme from the Themes page: seed colors, or a stylesheet that sets every step of a ramp. Do not change one step of a ramp alone.
API
Name Patterns
A semantic or component name says what the value is for. It never names a color or a shade number.
| Tier | Pattern | Example |
|---|---|---|
| Semantic | --{property}-{role}-{modifier}-{state} |
--text-oncolor-primary, --background-error-light |
| Component | --{component}-{property}-{variant}-{state} |
--button-background-primary-hovered |
Name Parts
| Part | Meaning |
|---|---|
primary, secondary, tertiary, neutral |
The brand and neutral roles |
success, info, warning, error |
The status roles. Each has background, text, border and icon tokens |
light |
A tint of the base meaning, for soft surfaces and borders |
faint |
The lightest tint, one step below light |
strong |
A deep, stronger form of the base meaning |
oncolor |
For an element on a colored or dark fill. It does not change in dark mode. It comes last, before the state |
default, hovered, pressed, selected, focused, disabled, checked |
The state. A name with no state is the resting state. pressed is the :active state |