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:
: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)
:root {
--cr-color-primary: #6d28d9;
}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.
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: darkadapts 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):
| Variable | Value |
|---|---|
--cr-color-primary-text | oklch(from var(--cr-color-primary) max(l, 0.8) c h) |
--cr-color-primary-indicator | oklch(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-overlay | rgba(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-m | 0 8px 24px rgba(0, 0, 0, 0.5) |
--cr-text-lightness-min | 0.8 |
--cr-text-lightness-max | 1 |
--cr-color-primary-subtle | color-mix(in oklab, var(--cr-color-primary) 22%, var(--cr-color-surface)) |
--cr-color-primary-subtle-hover | color-mix(in oklab, var(--cr-color-primary) 32%, var(--cr-color-surface)) |
--cr-color-focus | var(--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
| Variable | Value |
|---|---|
--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-overlay | rgba(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-hover | color-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-text | oklch(from var(--cr-color-primary) min(l, 0.47) c h) |
--cr-color-primary-subtle | color-mix(in oklab, var(--cr-color-primary) 12%, white) |
--cr-color-primary-subtle-hover | color-mix(in oklab, var(--cr-color-primary) 18%, white) |
--cr-color-on-primary | oklch(from var(--cr-color-primary) clamp(0, (0.62 - l) * 1000, 1) 0 0) |
--cr-color-primary-indicator | var(--cr-color-primary) |
--cr-color-focus | var(--cr-color-primary-text) |
Spacing
| Variable | Value |
|---|---|
--cr-spacing-xs | 4px |
--cr-spacing-sm | 8px |
--cr-spacing-lg | 16px |
--cr-spacing-xl | 24px |
--cr-spacing-2xl | 32px |
--cr-spacing-3xl | 48px |
Control heights
| Variable | Value |
|---|---|
--cr-control-xs | 30px |
--cr-control-s | 36px |
--cr-control-m | 40px |
--cr-control-l | 48px |
Typography
| Variable | Value |
|---|---|
--cr-font-family | system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif |
--cr-font-mono | ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace |
--cr-font-size-s | 12px |
--cr-font-size-m | 14px |
--cr-font-size-l | 16px |
--cr-font-weight-medium | 500 |
--cr-font-weight-bold | 600 |
Radii and shadows
| Variable | Value |
|---|---|
--cr-radius-m | 6px |
--cr-radius-l | 12px |
| Variable | Value |
|---|---|
--cr-shadow-m | 0 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;
}