Skip to Content
Cristal

Getting started

Theme

Adapt Cristal to your visual identity with one line of CSS.

Just one color to choose

To give the whole application your color, one line is enough, after importing @cristal-ui/react/tokens.css:

theme.css
:root {
  --cr-color-primary: #e11d48;
}

All the other shades are computed automatically from that color:

  • the hover shade (darker for a dark color, lighter for a light color);
  • the light background of secondary buttons and hovered options;
  • a version dark enough to be read as text, outline or focus indicator on a white background;
  • the color of text placed on the primary color: white on a dark color, black on a light color.

Theme builder

Pick a color and a corner radius: the preview updates, contrasts are checked, and all that is left is to copy the CSS.

Contrast (minimum 4.5:1)

    PrimarySecondaryOutlineLink
    :root {
      --cr-color-primary: #6d28d9;
    }
    Copy CSS

    A theme for part of the page

    Add the cr-theme class to a container and redefine the color on that container: only the components inside it change.

    <section className="cr-theme" style={{ '--cr-color-primary': '#0f766e' }}>
      <CrButton>Teal button</CrButton>
    </section>

    The builder checks the contrasts of your color. Mid-range colors (neither really light nor really dark) can stay below the 4.5:1 threshold: the builder then says so.

    Dark theme

    The dark theme is opt-in: import its stylesheet after the tokens, then set data-theme="dark" on <html>. Without that attribute nothing changes, even when the user's system is in dark mode: you decide when to turn it on.

    app/layout.tsx
    import '@cristal-ui/react/tokens.css';
    import '@cristal-ui/react/tokens-dark.css';
    
    <html lang="en" data-theme="dark">
    • Surface, text, borders, disabled states, danger, success, overlay and shadow take dark values, and color-scheme: dark adapts native controls and scrollbars.
    • Your primary color does not change: filled buttons keep your brand. Its derived shades adapt: text, focus outline and indicators (stars, slider, switch, checked box) switch to a light shade of your color, and the background of secondary buttons mixes with the dark surface instead of white.
    • Contrasts stay those of the light theme: at least 4.5:1 for text, 3:1 for borders, focus and indicators.

    The values that change in dark (the others stay those of the light theme):

    VariableValue
    --cr-color-primary-textoklch(from var(--cr-color-primary) max(l, 0.8) c h)
    --cr-color-primary-indicatoroklch(from var(--cr-color-primary) max(l, 0.68) c h)
    --cr-color-text#f3f4f6
    --cr-color-surface#111827
    --cr-color-disabled#2a3341
    --cr-color-on-disabled#9ca3af
    --cr-color-danger#f87171
    --cr-color-success#4ade80
    --cr-color-border#8b93a1
    --cr-color-text-muted#b4bbc6
    --cr-color-overlayrgba(0, 0, 0, 0.6)
    --cr-color-chart-1#9085e9
    --cr-color-chart-2#d95926
    --cr-color-chart-3#199e70
    --cr-color-chart-4#c98500
    --cr-color-chart-5#d55181
    --cr-color-chart-6#008300
    --cr-color-chart-7#3987e5
    --cr-color-chart-8#e66767
    --cr-shadow-m0 8px 24px rgba(0, 0, 0, 0.5)
    --cr-text-lightness-min0.8
    --cr-text-lightness-max1
    --cr-color-primary-subtlecolor-mix(in oklab, var(--cr-color-primary) 22%, var(--cr-color-surface))
    --cr-color-primary-subtle-hovercolor-mix(in oklab, var(--cr-color-primary) 32%, var(--cr-color-surface))
    --cr-color-focusvar(--cr-color-primary-text)

    For a single area, the cr-theme-dark class applies the dark theme to a container; cr-theme brings back the light theme there. In a dark page, give your local color with cr-theme-dark:

    <section className="cr-theme-dark" style={{ '--cr-color-primary': '#0f766e' }}>
      <CrButton>Teal button, dark version</CrButton>
    </section>

    To let users choose, the theme toggle sets the attribute, with an animated transition.

    Going further: all variables

    Every value is a CSS variable prefixed with --cr- that you can redefine. Derived colors show the formula that computes them.

    Colors

    VariableValue
    --cr-color-primary#6d28d9
    --cr-color-text#111827
    --cr-color-surface#ffffff
    --cr-color-disabled#e5e7eb
    --cr-color-on-disabled#6b7280
    --cr-color-danger#b91c1c
    --cr-color-success#15803d
    --cr-color-border#6b7280
    --cr-color-text-muted#4b5563
    --cr-color-overlayrgba(17, 24, 39, 0.5)
    --cr-color-chart-1#6d28d9
    --cr-color-chart-2#eb6834
    --cr-color-chart-3#1baf7a
    --cr-color-chart-4#eda100
    --cr-color-chart-5#e87ba4
    --cr-color-chart-6#008300
    --cr-color-chart-7#2a78d6
    --cr-color-chart-8#e34948
    --cr-color-primary-hovercolor-mix(in oklab, var(--cr-color-primary) 82%, oklch(from var(--cr-color-primary) clamp(0, (l - 0.62) * 1000, 1) 0 0))
    --cr-color-primary-textoklch(from var(--cr-color-primary) min(l, 0.47) c h)
    --cr-color-primary-subtlecolor-mix(in oklab, var(--cr-color-primary) 12%, white)
    --cr-color-primary-subtle-hovercolor-mix(in oklab, var(--cr-color-primary) 18%, white)
    --cr-color-on-primaryoklch(from var(--cr-color-primary) clamp(0, (0.62 - l) * 1000, 1) 0 0)
    --cr-color-primary-indicatorvar(--cr-color-primary)
    --cr-color-focusvar(--cr-color-primary-text)

    Spacing

    VariableValue
    --cr-spacing-xs4px
    --cr-spacing-sm8px
    --cr-spacing-lg16px
    --cr-spacing-xl24px
    --cr-spacing-2xl32px
    --cr-spacing-3xl48px

    Control heights

    VariableValue
    --cr-control-xs30px
    --cr-control-s36px
    --cr-control-m40px
    --cr-control-l48px

    Typography

    VariableValue
    --cr-font-familysystem-ui, -apple-system, 'Segoe UI', Roboto, sans-serif
    --cr-font-monoui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace
    --cr-font-size-s12px
    --cr-font-size-m14px
    --cr-font-size-l16px
    --cr-font-weight-medium500
    --cr-font-weight-bold600

    Radii and shadows

    VariableValue
    --cr-radius-m6px
    --cr-radius-l12px
    VariableValue
    --cr-shadow-m0 8px 24px rgba(17, 24, 39, 0.16)

    CSS parts

    For finer control, each component exposes parts that can be styled from outside with ::part(). They are listed at the bottom of each component page.

    cr-input.search::part(label) {
      color: white;
    }

    On this page