Skip to Content
Neshel-UI
Getting started

Customising tokens

Change colours, radius, spacing and fonts, add a named theme, and switch themes without a provider.

Design tokens are CSS custom properties such as --neshel-primary and --neshel-radius-base. Components only read tokens, so changing a token restyles everything that uses it.

Change the built-in themes

neshel.config.ts
import { defineConfig } from "@neshel-ui/config";

export default defineConfig({
  radius: { base: "0.5rem" },
  spacing: { unit: "0.25rem" },
  themes: {
    light: {
      colors: {
        primary: "#5b2a86",
        primaryForeground: "#ffffff",
        accent: "#e0a526",
        accentForeground: "#1f1300",
      },
    },
    dark: {
      colors: { primary: "#cfb3ff", primaryForeground: "#1b0a33" },
    },
    // A named theme for a marketing section, based on the light theme.
    sunrise: {
      extends: "light",
      colors: { background: "#fff7ed", foreground: "#3b1d00", primary: "#c2410c" },
    },
  },
  output: "./src/neshel.generated.css",
});

Run neshel generate. Contrast is checked for every foreground/background pair you change; failures are warnings by default and errors with --strict or contrast: "error".

Switch themes

Themes are selected with the data-neshel-theme attribute — no React provider:

<div data-neshel-theme="dark">
  <Button>Dark button</Button>
  <section data-neshel-theme="sunrise">
    <Button>Sunrise button inside a dark page</Button>
  </section>
</div>
Attribute valueResult
absentlight
light / darkforced, whatever the OS preference
systemfollows prefers-color-scheme
a named themeyour theme from neshel.config.ts

To let users choose, set the attribute on <html> from your own state and persist it (a cookie read on the server avoids a flash of the wrong theme).

Preview: theme-scopes
Preview theme

Theme “light”

Same components, different tokens.

Theme “dark”

Same components, different tokens.

Theme “evergreen”

Same components, different tokens.

Theme “aurora”

Same components, different tokens.

theme-scopes.tsx
import {
  Badge,
  Button,
  Card,
  CardContent,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@neshel-ui/components";
import { Grid } from "@neshel-ui/layout";
import { Paragraph } from "@neshel-ui/typography";

/**
 * Nested theme scopes: any element can set data-neshel-theme. "evergreen" and "aurora" are named
 * themes from this site's neshel.config.ts (generated by `neshel generate`).
 */
const themes = ["light", "dark", "evergreen", "aurora"] as const;

export default function ThemeScopes() {
  return (
    <Grid columns={{ base: 1, md: 2 }} space="4">
      {themes.map((theme) => (
        <div
          key={theme}
          data-neshel-theme={theme}
          className="rounded-xl bg-[var(--neshel-background)] p-4"
        >
          <Card>
            <CardHeader>
              <CardTitle>Theme “{theme}”</CardTitle>
            </CardHeader>
            <CardContent>
              <Paragraph size="sm" tone="muted">
                Same components, different tokens.
              </Paragraph>
            </CardContent>
            <CardFooter>
              <Button size="sm">Primary</Button>
              <Badge variant="accent">Accent</Badge>
            </CardFooter>
          </Card>
        </div>
      ))}
    </Grid>
  );
}

Neshel's navy and gold are only the defaults. See the Theming guide for the 25 colour roles, contrast pairs, fonts and the cascade. Next: Deploying an application.

Edit on GitHub

On this page