Skip to content
Focsd homeFocsd homeFocsd
Forms

Theming and tokens

Switch themes and density, re-theme Focsd with design tokens, and use the same tokens as Figma variables.

Every visual decision is a design token: a CSS custom property prefixed --focsd-. Components read only tokens, so changing a token changes every component that uses it.

Three themes ship in @focsd-dev/tokens: light, dark and contrast. Without an explicit theme, the tokens follow the system (prefers-color-scheme and prefers-contrast).

<html data-focsd-theme="dark">

A theme can apply to part of a page: set data-focsd-theme on any element and its descendants use that theme.

<body data-focsd-density="comfortable">

Three densities. Set data-focsd-density on <body> or on any section; default restores the standard size inside another density.

From script, setTheme('dark') and setDensity('compact', element) from @focsd-dev/tokens set the same attributes and reject unknown names; see Helpers for app code.

Density Controls Body text Labels and buttons Use for
default 36px 15px 14px Most web apps (the default, close to shadcn/ui)
comfortable 44px 17px 15px Touch-first apps, kiosks, and products for low-vision or older users
compact 32px 14px 13px Data-dense tools: admin consoles, dashboards, trading and monitoring

Every density keeps targets at 24px or more (WCAG 2.5.8 Target size, minimum). The data grid has its own row density toggle as well.

Density is the one size control for controls: buttons, icon buttons, badges and every field follow it, and they have no size attribute of their own. Where you do see size, it means one of two things:

  • On text-like fields (focsd-text-field, focsd-textarea, focsd-number-field, focsd-search-field, focsd-password-field, focsd-currency-field) it is the native size attribute: the field’s width in characters, as on <input>.
  • On a few components whose look has a scale of its own (focsd-avatar, focsd-spinner, focsd-segmented-control, focsd-dock, focsd-tag) it is s, m or l (the spinner adds xl). Targets stay within the density’s minimum at every size.

Four ready-made brands are one attribute away: <html data-focsd-brand="harbor">; see Theme presets. Focsd’s CSS sits in three cascade layers, declared in this order: focsd.tokens (the defaults), focsd.preset (a preset) and focsd.brand (your overrides).

@layer focsd.tokens, focsd.preset, focsd.brand;

Put your brand in focsd.brand and it beats a preset whatever the load order. The theme builder writes it that way.

Tier Example Use
Reference --focsd-ref-graphite-19 Raw palette values. Do not use in components.
System --focsd-action, --focsd-surface, --focsd-space-3, --focsd-radius-control Semantic roles. Re-theme here.
Component --focsd-button-background, --focsd-field-border-color Optional hooks for one component, with system fallbacks.

Override system tokens after loading tokens.css. Tokens live in the focsd.tokens cascade layer, so any unlayered rule of yours wins.

:root {
--focsd-action: #0b5cad;
--focsd-action-hover: #094a8b;
--focsd-on-action: #ffffff;
--focsd-route: #0b5cad;
--focsd-radius-control: 8px;
}
[data-focsd-theme='dark'] {
--focsd-action: #8cc4ff;
--focsd-on-action: #0b1220;
}

Some components read optional component tokens:

focsd-button {
--focsd-button-radius: 0;
}
focsd-text-field {
--focsd-field-background: var(--focsd-surface-sunk);
}

For anything else, style the component’s internals through CSS parts. Each component page lists its parts.

focsd-dialog::part(headline) {
font-size: 1.5rem;
}

@focsd-dev/tokens ships the same tokens as Figma variables, in the design tokens (DTCG) format Figma imports natively. Each file is one mode of one collection:

Collection Files Holds
Theme theme.light, theme.dark, theme.contrast Colors, and anything else that changes with the theme
Density density.default, density.comfortable, density.compact Control heights and other sizes that change with density
Base base Spacing, radii, type sizes and weights, durations, font families

Find them in node_modules/@focsd-dev/tokens/dist/figma/. In Figma’s Variables panel, import each file as the matching mode of its collection. Sizes are converted to pixels at a 16px root, and fluid type uses its largest size. Easing curves, shadows and letter spacing have no Figma variable type, so they are left out.

@focsd-dev/tokens/floor.css is an optional global stylesheet that applies the same baseline to your own markup: the two-tone focus ring on native controls, 24px minimum targets, forced-colors support, reduced motion and a .focsd-visually-hidden utility.