Customisation
Customise from broad to narrow: redefine tokens, generate a brand theme, restrict the picker, scope a subtree, or override an individual component. Each step is more local than the last.
The override ladder
- Tokens via CSS — set
--md-sys-*tokens on:rootfor the page and its overlays, on:root, [data-theme]for every theme (subtrees aThemeScopere-themes too), or on[data-theme="ocean"]for one (see Overriding tokens). - Component tokens — set M3's
--md-comp-*variables to restyle every instance of a component, globally or within a scope. - Brand theme — generate one with
createTheme()or the CLI. - Restrict the picker —
<ThemeProvider themes={['baseline', 'ocean', 'acme']}>. - Scope a subtree —
<ThemeScope theme="forest" mode="dark">. - Component level —
className/classNames={{ root, label, icon }}, or extend the exported variant definitions.
Steps 1 and 3–5 are covered in the Theming guide. This page covers component tokens (step 2) and the component level (step 6).
Component tokens
Components with tokens read M3's component tokens as CSS variables, named after M3's own md.comp.* tokens with the dots as dashes: md.comp.filled-card.container.color is --md-comp-filled-card-container-color. Each is unset until you set it, and falls back to the system token the component uses by default. A component's API tab lists its tokens, their defaults and what they paint (Card's Tokens).
- Declare role values on
:root, [data-theme]. A value that reads another variable resolves where it's declared: on:rootalone,var(--md-sys-color-secondary-container)would keep the root theme's colour inside a dark or differently themedThemeScope. A ThemeScope or overlay that changes the theme, mode or contrast carriesdata-theme, so the value resolves again there. - A literal value (
#0050c8,4px) is the same in every theme, mode and contrast level. Check a literal colour's contrast yourself. - Set them on the component or an ancestor, never on an inner slot: the component resolves its tokens on its root.
- Icon colour in a container:
--md-comp-icon-button-icon-color(M3's baseline name) colours every standard and outlined icon button inside the element that sets it; the per-variant--md-comp-icon-button-standard-icon-colorand--md-comp-icon-button-outlined-icon-colorcome first. App bars, search bars and vibrant toolbars set it tocurrentColor, so their icons follow their own text colour. - Overlays portal to
body, so tokens set on an arbitrary ancestor don't reach them. Tokens on:root, on[data-theme], on the overlay's ownclassName, or through the class or the inlinestylevariables of aThemeScopearound it do. - Precedence: system token, then component token, then
classNameandclassNames, which still win. - Styling hooks: a component with tokens marks its root with the props its tokens depend on:
data-variant,data-sizewhere it has sizes, and a few others such as the FAB'sdata-color. They're public, so your own selectors can use them ([data-variant="outlined"]).
import { Card, ThemeScope } from '@windmorph/react';
// A ThemeScope's class and the CSS variables of its style also go on the
// overlays opened inside it (menus, dialogs, tooltips), so tokens set through
// either reach them.
<ThemeScope className="compact">
<Card variant="elevated">…</Card>
</ThemeScope>;
// One instance: set the variable on the component itself.
<Card className="[--md-comp-filled-card-container-color:var(--md-sys-color-tertiary-container)]">
…
</Card>;Coming from Material Web
Material Web names the same tokens without comp-: its --md-outlined-card-outline-color is Windmorph's --md-comp-outlined-card-outline-color, and --md-icon-button-icon-color is --md-comp-icon-button-icon-color. Windmorph follows M3's current token tables, which are newer than Material Web, so:
- Where M3 Expressive renamed a component's tokens, Windmorph uses the new name. The component's Tokens table is the reference.
- Expressive sizes have their own shapes, so a single
container-shapebecomes one per size where M3 has sizes. - Expressive-only tokens, such as a toggle button's
selected-*andunselected-*colours, have no Material Web equivalent. - Typography, state-layer, disabled and spacing tokens aren't exposed. Use
--md-sys-typescale-*,classNameorclassNames, and thesizeprop.
className & classNames
Every component takes className for its outermost element and classNames for its named slots (for example a button’s root, content, label and icon). The consumer’s class always wins.
import { Button } from '@windmorph/react';
// A consumer className always wins over the library's conflicting class (via cn()).
<Button variant="filled" className="rounded-corner-full px-8">Rounded</Button>;
// Per-slot overrides with classNames.
<Button classNames={{ root: 'shadow-none', label: 'tracking-wide', icon: 'text-primary' }}>
Save
</Button>;Extending variants
Each component exports its variant recipe as a *Styles definition — buttonStyles, iconButtonStyles, cardStyles, chipStyles, textFieldStyles, menuStyles and many more. Compose a new variant on top of one with tv (a pre-configured tailwind-variants re-export) and VariantProps.
import { tv, buttonStyles } from '@windmorph/react';
import type { VariantProps } from '@windmorph/react';
// Extend an exported *Styles recipe with a new variant using tv (tailwind-variants,
// pre-configured with the M3 twMergeConfig).
const brandButton = tv({
extend: buttonStyles,
variants: {
color: { brand: 'bg-tertiary text-on-tertiary', muted: 'bg-surface-container' },
},
defaultVariants: { color: 'brand' },
});
type BrandButtonProps = VariantProps<typeof brandButton>;Why the consumer wins: cn()
cn() is tailwind-merge extended with the library’s theme keys — colour roles, type roles, corner-* radii, elevation-* shadows, and m3-* easings and durations. Later classes override earlier conflicting ones, which is why a className you pass always beats the library’s own class for that property.
import { cn } from '@windmorph/react';
// cn is tailwind-merge extended with the M3 theme keys (colour roles, type roles,
// corner-* radii, elevation-* shadows, m3-* easings and durations). Later classes win,
// so a consumer class always overrides a conflicting library class.
cn('bg-primary', 'bg-secondary'); // -> 'bg-secondary'
cn('rounded-corner-small', 'rounded-corner-large'); // -> 'rounded-corner-large'Layout safety
A component’s internals never depend on the root’s position, overflow, display or transform, so you can put any layout class on any component and it looks and behaves the same.
classNameandstylealways land on the outermost element;styleis merged, never replaced.- To animate a button’s size or position, put the transition on a wrapper: while pressed, the button’s own motion replaces the timing of a transition added through
className. - State layer and ripple are painted as background layers, so they follow
border-radiusand need neitherrelativenoroverflow-hidden. - Motion never animates the root’s
transform, and containers never settransform/filter/contain/will-changeon their root, sofixedchildren are never trapped. - The focus ring is a CSS
outline, so anoverflow-hiddenon the component itself can’t clip it. An ancestor that clips its overflow still can, so leave room around focusable items.
import { Button, DockedToolbar } from '@windmorph/react';
// className / style land on the outermost element, so any layout class is safe:
<Button className="fixed bottom-4 right-4">New</Button>;
<DockedToolbar aria-label="Actions" className="fixed inset-x-0 bottom-0 w-full">
…
</DockedToolbar>;Three documented exceptions: overlays portal to body on a z-index token scale (--md-sys-z-*, which you can override); scroll-driven app bars and toolbars manage their own expansion (useToolbarScrollExpansion, TopAppBarScrollBehavior); and a FAB or toolbar that you hide (visible={false}) scales or slides with a transform on its root while hidden. That uses the transform property only, so Tailwind's translate-* and scale-* classes still apply.