---
name: theming-vela-ui
description: Themes and restyles Vela charts and @luxalgo/vela-ui components with createTheme - brand colors, light, dark and custom themes, design tokens, component settings, part-by-part CSS restyles, scrollbars, cascade layers and theme JSON files checked with checkTheme. Use when the user wants a chart or its menus, dialogs and controls to match a brand or design system, asks for a new theme, a color or radius change, a component restyle or a CSS override that does not stick, even if they only say "make the chart look like our app".
license: Apache-2.0
title: theming-vela-ui
canonical_url: https://skilld.dev/gh/luxalgo/vela/theming-vela-ui
last_updated: 2026-11-12T02:47:19.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install luxalgo/vela/theming-vela-ui`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/theming-vela-ui`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/luxalgo/vela/theming-vela-ui) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/theming-vela-ui`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/theming-vela-ui --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/theming-vela-ui --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Theming Vela and vela-ui

A theme is data built by `createTheme`. One theme reaches the chart's canvas (candles, grid,
axis text), Vela's chrome (toolbars, menus, dialogs) and every kit component.

## Where a change belongs

Pick the first row that can express the change; each later row is more specific and more
work to maintain.

| To change | Use |
| --- | --- |
| Background, text, candles, grid | `createTheme({ colors: { background, text, grid, border, up, down } })`; light or dark is read from the background |
| Brand color, corner roundness, font | `accent` (the same choice as `colors.accent`; the top-level one wins), `radius` (`none`, `sm`, `md`, `lg`), `font` |
| One design token | `tokens: { 'surface-elev': '#1b1c22' }` (name without `--vela-`) |
| One component's sizes, radius or colors | `components: { button: { radius: '2px' } }` (its settings) |
| A component's whole look | ``components: { button: { css: { root: css`…`, icon: css`…` } } }`` (its parts) |
| Scrollbars | tokens `scroll` (thumb color) and `scroll-size` (width) |

Token names, layers and the full rules are in `node_modules/@luxalgo/vela-ui/docs/theming.md`.
A component's settings, parts and the state attributes its CSS keys on are in
`node_modules/@luxalgo/vela-ui/dist/manifest.json` (`settings`, `parts`, `attributes`).

## Workflow

Copy this checklist and tick it off:

```
- [ ] 1. Start from colors: createTheme({ colors, accent, radius, font })
- [ ] 2. Adjust single tokens only where the derived ones miss
- [ ] 3. Use component settings before part CSS
- [ ] 4. Write part CSS with the css tag, against parts and data attributes
- [ ] 5. Run checkTheme(input) and fix every problem it names
- [ ] 6. Apply it (Vela: theme option or setTheme; elsewhere: ensureUIHost)
- [ ] 7. Check computed styles in the browser, menus and dialogs opened
```

## Applying a theme

In a Vela project, the theme functions come from `@luxalgo/vela`, and the `css` tag and the
tokens `t` from `@luxalgo/vela/ui`. In a project of components only, all of them come from
`@luxalgo/vela-ui/theme` (`css` and `t` from `@luxalgo/vela-ui`).

```ts
import { checkTheme, createTheme, registerTheme, type ThemeInput } from '@luxalgo/vela';
import { VelaWorkspace } from '@luxalgo/vela/workspace';

const input: ThemeInput = { colors: { background: '#0f1117', text: '#c9d1d9' }, accent: '#7c3aed', radius: 'md' };
const problems = checkTheme(input); // [] when every name is right; runs without a page, so in tests too
if (problems.length) console.warn(problems);
const brand = createTheme(input);

registerTheme({ id: 'brand', label: 'Brand', theme: brand }); // optional: lists it in chart settings
new VelaWorkspace('#chart', { symbol: 'BTCUSDT', theme: brand }); // or ws.setTheme(brand) later
```

On a page of components without a chart: `ensureUIHost(el, theme)` from
`@luxalgo/vela-ui/theme`. `applyTheme(el, theme)` only switches a host that already is one.

## Restyling a component by its parts

```ts
import { createTheme, css, t } from '@luxalgo/vela/ui'; // or '@luxalgo/vela-ui'

const theme = createTheme({
    components: {
        button: {
            radius: '999px',
            css: {
                root: css`
                    text-transform: uppercase;
                    &[data-variant='outline'] { border-width: 2px; }
                    &:not(:disabled):hover { box-shadow: ${t.shadow}; }
                `,
            },
        },
    },
});
```

- **Write it with the `css` tag.** CSS not written with the tag (a theme loaded from JSON) is
  dropped unless you pass `createTheme(input, { allowCss: true })`, and only do that for CSS
  you trust. A plain string still typechecks: `checkTheme` is what catches a missing tag.
- **A part's CSS overrides the component's own declarations it repeats.** A `background`
  shorthand on a fill erases the color the component sets for its state: add to it
  (`background-image`) or key the rule on the state attribute.
- **`&` is the part.** Key states on its data attributes (`data-state`, `data-selected`,
  `data-highlighted`, `data-variant`, `data-size`), never on class names, never `!important`.
- **A state can live on another part.** The switch's `data-state` sits on its root, so style
  the track from the root: ``root: css`&[data-state='checked'] [data-slot~='switch-control'] { … }` ``.
- **One level of nesting**, plus `@media`, `@supports` and `@container`. Declare `@keyframes`
  and `@font-face` in the page's stylesheet and use them by name.

## Gotchas

- **A misspelled component, setting or part does nothing.** `checkTheme(input)` names it,
  and `createTheme` warns about it once in the console. Run it on every theme you write.
- **`components.button` restyles the kit's buttons** (in dialogs, panels, your own UI). Vela's
  toolbars are its own chrome: tokens reach them, component settings do not.
- **Tokens derived from a `var()` cannot be computed.** When a color comes from the host's
  CSS variables (`accent: 'var(--primary)'`), also set the tokens derived from it, such as
  `'focus-soft'` and `'fg-on-fill'`.
- **Page CSS outside any layer beats the whole kit.** A global reset such as
  `button { background: none; }` now restyles the kit's buttons too: scope it with
  `button:where(:not(.vela-ui *))` or move it into a layer declared first (`@layer reset;`).
- **Native scrollbars inside the chart** mean the page sets `scrollbar-width` or
  `scrollbar-color` on every element; reset them for `.vela-ui, .vela-ui *`.
- **Your own components** put their base styles in `@layer vela.ui` so the theme's part CSS
  (in `vela.custom`) can restyle them; see the `writing-vela-ui-components` skill.

## Themes as JSON files

A theme of colors, tokens and settings is plain JSON. Point it at the schema so editors and
CI validate it, then load it with `createTheme(json)`:

```json
{
    "$schema": "./node_modules/@luxalgo/vela-ui/dist/theme.schema.json",
    "colors": { "background": "#fdf6e3", "text": "#586e75", "accent": "#268bd2" },
    "radius": "none"
}
```

`npx @luxalgo/vela-ui check` validates the file named by `theme` in `vela-ui.json` at the
project root.

## Check your work

1. `checkTheme(input)` returns an empty list.
2. In the browser, read the result, not the source: `getComputedStyle(el)` on a restyled
   part, with menus and dialogs opened, since they only exist while open.
