Customize the look
Start from the shallowest layer and go deeper only when it isn't enough:
- Design tokens (
--ui-*) for sizes and colors - Theme zones (
data-theme, see Themes and layers) ::part()for one piece of an element- Slots for markup in labels and help text
- A derived class as the last resort
The shallower layers survive upgrades better, because they don't depend on how an element is built inside. Attributes, properties, events, slots, parts and --ui-* tokens listed in api.md are not removed or renamed before the next major version. Selectors inside the shadow DOM are not part of that promise.
Change sizes and colors with tokens
Every component reads CSS custom properties named --ui-* from tokens.css (loaded once per page). Set them on :root to change the whole app, or on any element to change only what's inside it. You don't touch the shadow DOM:
The React + Tailwind classes read the same tokens (see below), so a token set on a wrapper changes them too. Headless parts have no look, so tokens don't apply to them.
The public tokens that components read:
| Token | Changes |
|---|---|
--ui-field-height-sm, -md, -lg |
Field height per size (32 / 40 / 48px): text input, select, dropdown, combobox, multi-select, date picker, button |
--ui-menu-max-rows |
Rows a dropdown, combobox or multi-select menu shows before it scrolls (5.5) |
--ui-calendar-width |
Width of the date picker's calendar (288px) |
--ui-sheet-radius |
Top corners of the date picker's bottom sheet on phones (the menu radius) |
--ui-available-height, --ui-available-width |
Written on an open list or menu while it is open: the room left beside its field. Its max-height takes it, so a long list scrolls inside the screen. Read it in your own popup's CSS; don't set it |
--ui-highlight |
Color of the selected days in a range picker |
--ui-surface-1, --ui-surface-2, --ui-hairline, --ui-ink-subtle, --ui-ghost-hover, --ui-ghost-active |
Layer tokens: they point at the current layer's set, and <ui-layer> moves them |
--ui-primary, --ui-ink, --ui-canvas, --ui-focus, … |
Theme colors, each made from the Carbon token named at the end of its line in tokens.css |
Each element's own list is under "Design tokens" in api.md and in the CSS custom properties table of its Storybook page.
Change one piece of an element with ::part()
::part(name) styles a piece an element exposes. Part names are the same words across components: base, label, input, menu, option, helper-text, error-text, … The date picker passes on the parts of the fields inside it; in range mode they get start- and end- in front:
Every element's parts are listed in api.md. ::part() is for the web components and the React wrappers, which render them. React + Tailwind and headless have no shadow DOM: give the pieces classes instead (the last two sections).
A few elements have no pieces inside: ui-toaster, ui-fluid-form, ui-button-set, ui-badge-indicator and ui-stack are the box you see. Style them with plain CSS on the element, e.g. ui-stack { row-gap: 24px; } or ui-badge-indicator { background: var(--ui-info); }: page CSS wins over their own. ui-button-set also has the part button-set (as in Carbon), but its layout is on the element.
Style by state
You can read every state that changes the look from the element itself, and combine it with ::part():
- Properties you or the user change are reflected as attributes:
open,checked,selected,expanded,invalid,warn,size,kind, … - States the element works out itself are set as
data-*attributes on the element:
| Attribute | Means | On |
|---|---|---|
data-open |
The list or calendar is open | ui-dropdown, ui-combobox, ui-multi-select, ui-date-picker |
data-show-error, data-show-warn |
The error or warning is actually showing (an error replaces a warning) | every form field |
data-has-value |
There is text or a selection | ui-combobox, ui-multi-select, ui-search |
data-placeholder |
The placeholder is showing | ui-dropdown, ui-select |
data-password-visible |
The password is shown | ui-text-input type="password" |
data-editing |
In edit mode | ui-edit-in-place |
data-drag-over |
A file is dragged over the drop zone | ui-file-uploader |
data-shown |
The spinner or overlay really shows (after delay) |
ui-loading |
data-overflowing |
The text is cut off | ui-truncated-text |
Each of these is also a custom state, as on native and Web Awesome elements: ui-dropdown:state(open) matches exactly when ui-dropdown[data-open] does (:state(show-error), :state(has-value), …). Use whichever you prefer; the attribute works in older browsers too. Each element's states are listed in its API reference.
Click into the email field and leave it empty, then open the dropdown:
Use [data-show-error] rather than [invalid] to style the error the user actually sees. invalid is the value you set: it stays on a disabled field, which shows no error, and it doesn't include errors from the user's own input.
The data-* states are set after the first render in the browser, so HTML rendered on a server doesn't have them yet. The headless parts show their state with data-* attributes of their own: see Headless.
Put markup in labels and help text with slots
When text needs a link, bold text or an icon, use a slot instead of the attribute of the same name. The attribute still works as plain-text fallback.
Every field takes the label, helper-text, warn-text and invalid-text slots. data-description on an <option> adds a second line in a dropdown, combobox or multi-select. Other elements have their own, such as header-actions on ui-modal and end on ui-tabs; api.md lists them all. React + Tailwind has no slots: label, helperText, warnText and invalidText take markup, and an item's description is its second line.
Change the shape with a derived class
The last resort, for what tokens, parts and slots can't do, and only for the web components. Extend the element's class and add your styles after its own. You keep all its behavior (forms, keyboard, accessibility):
Internal selectors are not public API. Select by [part=…], as above: it survives upgrades better than internal class names.
React + Tailwind: edit the copied classes
With shadcn the component's source is copied into your app, so you change its look where it is written. Each file keeps its classes in plain Tailwind (cva variants for kinds and sizes). For example, in components/ui/react-tw/button.tsx:
For one place only, pass className. Classes are merged with tailwind-merge, so the ones you pass win:
The classes (bg-primary, text-ink, h-field-md, rounded-pill, …) come from theme.css, which maps the --ui-* tokens into Tailwind's theme. Tokens and data-theme zones therefore work here exactly as for the web components. The behavior (keyboard, focus, ARIA) comes from @purpurabog/ui/headless and keeps updating with the package.
Headless
The headless parts render no classes and read no tokens: you style them on their data-* state attributes. See Headless.