---
title: "Restyle with tokens"
description: "Re-theme every packaged component with the --bk-* tokens on :root inside @layer nuxt-backend-tokens, give it your faces, tracking, lines, shadows and a button that presses, reach every component with one [data-backend] selector, follow light and dark, and style state through the data-* hooks."
canonical_url: "https://nuxt-backend.dev/docs/build/ui/customize/tokens"
---
# Restyle with tokens

> Re-theme every packaged component with the --bk-* tokens on :root inside @layer nuxt-backend-tokens, give it your faces, tracking, lines, shadows and a button that presses, reach every component with one [data-backend] selector, follow light and dark, and style state through the data-* hooks.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

Give the packaged pages your accent colour and corners with three lines of CSS. Every packaged component draws its colours, radii, faces, lines and shadows from `--bk-*` custom properties, and exposes its state as `data-*` attributes. The package declares the tokens on `:root` inside `@layer nuxt-backend-tokens`, the lowest layer there is, so a token you set anywhere wins with no specificity to match, and the package CSS loads only for the capabilities your app uses.

## The `--bk-*` tokens

Override them on `:root` in any stylesheet of your app:

```css [app/assets/css/main.css]
:root {
  --bk-accent: #6d5dfc;
  --bk-on-accent: white;
  --bk-radius: 10px;
}
```

```ts [nuxt.config.ts]
export default defineNuxtConfig({
  modules: ['nuxt-backend'],
  css: ['~/assets/css/main.css'],
})
```

Twenty-eight tokens carry every colour, radius, face, line, shadow and press: the accent and the text on it, ink, muted text, edges, surfaces, the error, ok and warn signals, two radii, three faces, three trackings, three outline widths, three shadows and the five press states. [Tokens and data hooks](https://nuxt-backend.dev/docs/reference/components/theme-tokens) lists each with its light and dark default and the families that read it.

The defaults carry no brand colour: green means go (the accent and the ok tone), yellow warns and red is an error. Each fixed colour is a `light-dark()` pair, and on a wide-gamut screen each signal gains the chroma that screen can show. The neutral tokens mix from `currentColor`, so they follow your text colour. Check the contrast of colours you pick: the defaults pass WCAG 2.2 AA in both schemes, and yours must too ([Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility#what-this-means-for-you)).

## Faces, lines and shadows

The tokens past colour give a page with a typeface and a drawn line of its own its lettering, its lines and a button that presses:

```css [app/assets/css/main.css]
:root {
  --bk-font-heading: var(--font-display);
  --bk-font-control: var(--font-display);
  --bk-tracking-heading: 0.02em;
  --bk-tracking-control: 0.04em;
  --bk-tracking-label: 0.1em;
  --bk-border-width: 2px;
  --bk-border-width-surface: 3px;
  --bk-shadow: 4px 4px 0 var(--ink);
  --bk-shadow-control: 2px 2px 0 var(--ink);
  --bk-shadow-control-hover: 4px 4px 0 var(--ink);
  --bk-shadow-control-active: none;
  --bk-offset-control-hover: -1px -2px;
  --bk-offset-control-active: 2px 2px;
  --bk-shadow-overlay: 6px 6px 0 var(--ink);
  --bk-transition-control: translate 120ms ease-out, box-shadow 120ms ease-out;
}
```

- **Faces.** `--bk-font` is the face of a component's text, `--bk-font-heading` of its headings and `--bk-font-control` of its buttons, each defaulting to `inherit`, your page's face. A heading or a button whose token you leave unset reads `--bk-font`. The face rules sit in `nuxt-backend-tokens`, the lowest layer, so a heading face of yours in any layer, such as Tailwind's `base`, still wins. Sizes and weights stay each component's. A display face that ships one weight is drawn in a fake bold where a button asks for 600: add `font-synthesis-weight: none` on `[data-backend]` (below), and the browser keeps the weight the face has.
- **Tracking.** `--bk-tracking-heading` is the letter-spacing of headings, `--bk-tracking-control` of buttons, and `--bk-tracking-label` of the small uppercase labels (section titles, badges, the "or" between two sign-in choices), which want a wider tracking than a large title, for a display face that wants its own. Unset, a heading keeps the page's, and a button, or a link drawn as one, keeps what your page, your reset (Tailwind's preflight makes it inherit) and the browser give it: the components set none. A heading or a label with a tracking of its own, such as a page title's or a badge's, keeps it until you set its token.
- **Lines.** `--bk-border-width` is the width of every outline the components draw: a button's, a field's, a card's, a dialog's, and the ring around the current plan. `--bk-border-width-surface` overrides it for what holds content (cards, banners, panels, dialogs, the plan ring) and `--bk-border-width-control` for what you press or type in (buttons, fields, chips), so a panel can take a heavier line than its buttons. Each falls back to `--bk-border-width`. A divider on one side of a row stays `1px`.
- **Shadows.** `--bk-shadow` sits under cards, banners and panels, `--bk-shadow-control` under buttons drawn as buttons (an outline or a fill; a text button has none), and `--bk-shadow-overlay` under what floats above the page: dialogs, menus and popovers. The first two default to `none`.
- **The press.** A button drawn as a button takes `--bk-shadow-control-hover` and moves by `--bk-offset-control-hover` (a `translate` value) under the pointer, then `--bk-shadow-control-active` and `--bk-offset-control-active` while pressed; a press you leave unset keeps the hover's, and a hover you leave unset keeps the resting shadow and does not move. A disabled or busy button and a text button never press. `--bk-transition-control` is the `transition` between the states, none while unset. For someone who asked for less motion (`prefers-reduced-motion: reduce`), the shadow still changes, but nothing moves or transitions. A screen without a hovering pointer takes no hover state, so a tapped button doesn't stay lifted, and the press shows while the finger is down. A state belongs to the element in it: a drawn button inside a hovered link or label doesn't take the hover.

A multi-line field (the contact message, a cancellation comment) keeps the card corners, `--bk-radius`, whatever `--bk-radius-control` says: a pill reads as one line.

## One selector for every component

The outermost element of every packaged component and page carries `data-backend`. Where a token is not enough, one selector reaches them all, instead of a list of families:

```css [app/assets/css/main.css]
:where([data-backend]) {
  font-synthesis-weight: none;
}

:where([data-backend]) :where(h1, h2, h3, button) {
  font-weight: 400;
}
```

A rule like these restyles an element, not a token, so it sits outside a layer, or in a layer declared after `nuxt-backend` ([Packaging](#packaging)). `:where()` keeps its specificity at zero, so a family rule of yours still wins over it. [Tokens and data hooks](https://nuxt-backend.dev/docs/reference/components/theme-tokens#the-root-attribute) says what the attribute marks.

## Scope a change to one family

To re-theme one component and leave the others, override the tokens on its family root:

```css [app/assets/css/main.css]
[data-pricing='table'] {
  --bk-accent: #b45309;
}
```

Some families read tokens of their own, each defaulting to the shared one (`--auth-accent: var(--bk-accent)`), so `--auth-accent` changes the sign-in form alone. [Tokens and data hooks](https://nuxt-backend.dev/docs/reference/components/theme-tokens#families) lists every family token.

## Follow light and dark

The package never sets `color-scheme`; your app owns it. Declare it in a stylesheet, and every `light-dark()` pair follows:

```css [app/assets/css/main.css]
:root {
  color-scheme: light dark;
}

/* A colour mode that puts a class on <html>, such as @nuxtjs/color-mode: */
:root.dark { color-scheme: dark; }
:root.light { color-scheme: light; }
```

With no scheme declared, each pair takes its light value. Declare the scheme in CSS, not only in a `<meta name="color-scheme">` tag: a production build rewrites `light-dark()` for older browsers, and the rewritten pairs follow only the `color-scheme` rules they find in CSS.

## `data-*` families

Each component has a family: `<PricingTable>` renders `data-pricing` on every element, `<WorkspaceSettings>` renders `data-settings`. The family's value names the element: the root is `[data-pricing='table']`, a plan card `[data-pricing='plan']`, a packaged page's `<main>` `[data-pricing='page']`.

State is exposed the same way on every component:

<table>
<thead>
  <tr>
    <th>
      Attribute
    </th>
    
    <th>
      Present when
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        data-state
      </code>
    </td>
    
    <td>
      The element's step or status, such as <code>
        idle
      </code>
      
      , <code>
        pending
      </code>
      
      , <code>
        open
      </code>
      
      , <code>
        closed
      </code>
      
      , <code>
        checked
      </code>
      
       or <code>
        unchecked
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-disabled
      </code>
    </td>
    
    <td>
      A control cannot be used right now. It still keeps focus (<code>
        aria-disabled
      </code>
      
      )
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-invalid
      </code>
    </td>
    
    <td>
      A field was refused, beside <code>
        aria-invalid
      </code>
      
       and its description
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-loading
      </code>
    </td>
    
    <td>
      A region waits for data, beside <code>
        aria-busy
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        data-current
      </code>
      
      , <code>
        data-intent
      </code>
      
      , <code>
        data-tone
      </code>
    </td>
    
    <td>
      The current plan or session, a pricing action's intent, a message's tone (<code>
        ok
      </code>
      
      , <code>
        error
      </code>
      
      , <code>
        warn
      </code>
      
      )
    </td>
  </tr>
</tbody>
</table>

```css [app/assets/css/main.css]
[data-pricing='plan'][data-current] {
  outline: 2px solid var(--bk-accent);
}

[data-auth='input-code'][data-invalid] {
  border-color: var(--bk-error);
}

[data-loading] {
  opacity: 0.6;
}
```

Style on these hooks, never on a role: an error is `role="alert"` whatever it looks like. Every button and link gets a `:focus-visible` ring in `--bk-accent`. [Tokens and data hooks](https://nuxt-backend.dev/docs/reference/components/theme-tokens#families) lists every family with its elements.

## Packaging

- **Two layers.** The token defaults sit in `@layer nuxt-backend-tokens`, and every other package rule in `@layer nuxt-backend`. The stylesheet opens by declaring the order `@layer nuxt-backend-tokens, theme, base, reset, nuxt-backend;`. The token defaults sit below everything, so a token you set wins wherever you set it: outside a layer, in Tailwind's `@theme`, or in a `theme`, `base` or `reset` layer of your own. Tailwind's theme and reset, and a `reset` layer of yours, sit below the package's rules, so a preflight never strips its buttons, and every layer declared after it sits above them. A rule of yours outside a layer always wins, and so does one in Tailwind's `components` or `utilities`.
- **Resets.** A reset outside a layer, such as `button { background: none }`, also wins over the package and strips its buttons. Put resets in the `reset` layer:```css [app/assets/css/main.css]
@import './reset.css' layer(reset);
```
- **Only what you use.** Each component and part has a stylesheet of its own, and the module loads those of the capabilities it detects: the tokens and the auth, account, workspace and shell styles always, the billing ones once `backend/billing.ts` exists. No billing, no pricing CSS.
- **None at all.** `backend: { css: false }` loads no package CSS ([Customization ladder](https://nuxt-backend.dev/docs/build/ui/customize)).

## What happens when…

<table>
<thead>
  <tr>
    <th>
      Situation
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      You set a token inside <code>
        reset
      </code>
      
      , <code>
        base
      </code>
      
       or <code>
        theme
      </code>
    </td>
    
    <td>
      Yours wins: the package's defaults sit in the lowest layer
    </td>
  </tr>
  
  <tr>
    <td>
      You restyle a packaged element (not a token) inside <code>
        reset
      </code>
      
      , <code>
        base
      </code>
      
       or <code>
        theme
      </code>
    </td>
    
    <td>
      The package's rule wins: those layers sit below <code>
        nuxt-backend
      </code>
      
      . Put the rule outside layers, or in a layer declared after <code>
        nuxt-backend
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      You override a signal colour
    </td>
    
    <td>
      Its wide-gamut tiers are replaced too
    </td>
  </tr>
  
  <tr>
    <td>
      A family has no token of its own
    </td>
    
    <td>
      It reads the shared <code>
        --bk-*
      </code>
      
       token
    </td>
  </tr>
</tbody>
</table>

## Limits

- **No theme bridge.** The package reads no UI library's variables. Map them yourself: `--bk-accent: var(--color-primary)`.
- **No spacing, size or weight tokens.** Spacing, type sizes and weights stay each component's; set them through `[data-backend]`, the family roots or the `data-*` hooks.

## Test it

Open `/pricing`, override `--bk-accent` in the browser's developer tools on `:root`, and every packaged button follows. Then run the axe check in your end-to-end suite in both schemes ([Run end-to-end tests](https://nuxt-backend.dev/docs/develop/testing/e2e)).

## Related

- [Tokens and data hooks](https://nuxt-backend.dev/docs/reference/components/theme-tokens): every token and family, generated from the code.
- [Customization ladder](https://nuxt-backend.dev/docs/build/ui/customize): when tokens are not enough.
- [Customize with slots](https://nuxt-backend.dev/docs/build/ui/customize/slots): when a region needs more than styling.
- [Accessibility](https://nuxt-backend.dev/docs/build/ui/accessibility): the contrast and focus the defaults keep.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
