Theming
Learn how to utilize Crispy's theming system in a Lynx environment.
Overview
Crispy provides a theming system that supports light mode and dark mode. Whether you use Vanilla Extract or Tailwind CSS v4, the following root theme configuration applies commonly.
In web environments, themes are controlled through data-* attribute selectors, but Lynx doesn't support data-* attribute selectors, so CSS class names are used.
CSS custom properties (variables) declared in stylesheets are inherited in Lynx as well, so theme tokens set on root elements naturally apply to child elements.
Apply Global Configuration
Set the theme class on the <page> element using the getSeedClassName() function from @seed-design/lynx-react.
getSeedClassName() returns seed-user-color-scheme-light or seed-user-color-scheme-dark class depending on the colorMode option.
colorMode Option
colorMode Setting | Device Setting | Applied Theme Class |
|---|---|---|
system (default) | Light mode | seed-user-color-scheme-light |
system | Dark mode | seed-user-color-scheme-dark |
light-only | (irrelevant) | seed-user-color-scheme-light |
dark-only | (irrelevant) | seed-user-color-scheme-dark |
When set to system, it reads the lynx.__globalProps.theme value and follows the device's dark mode setting.
Understanding Theme Classes
Crispy's Lynx theming system uses two types of class names.
seed-user-color-scheme-* (Root Level Theme)
The class applied by getSeedClassName() to the <page> element. Represents the currently resolved theme.
seed-user-color-scheme-light: Light mode is appliedseed-user-color-scheme-dark: Dark mode is applied
seed-color-mode-*-only (Child Level Override)
Class used to force apply a theme to a specific element and its child elements.
seed-color-mode-light-only: Force the area to light modeseed-color-mode-dark-only: Force the area to dark mode
How It Works
Crispy CSS applies appropriate color tokens through combinations of class names:
- The
:rootselector alone applies light mode tokens by default. - The
:root.seed-user-color-scheme-*selector handles the global theme set on the root element. - The
.seed-color-mode-*-onlyselector handles theme overrides in child elements. It includes selectors both with and without the:rootprefix, so it works in both root and child elements.
Using with Vanilla Extract
After importing @seed-design/lynx-css/base.css, reference tokens from @seed-design/lynx-css/vars in .css.ts.
Tokens are CSS variable references, so colors change according to the root theme without directly specifying color values.
See the Vanilla Extract guide for the plugin and CSS import configuration.
Using with Tailwind CSS
If you chose Tailwind CSS v4, you can use Crispy tokens with @seed-design/tailwind4-theme. Existing v3 projects use @seed-design/tailwind3-plugin.
v3 classes directly reference var(--seed-color-*). The v4 theme declares --color-* aliases at the root, which the utilities reference. Use it together with the theme on the root <page>.
In v4, even if you apply seed-color-mode-dark-only and similar classes to a
child element, the Tailwind alias defined at the root may not re-reference
the Crispy token for that area.
In that case, the color of the Tailwind utility and a direct token reference will differ.
The v4 configuration described here is based on the root theme, and overriding a sub-area is not within its supported scope.
Also check the v4 configuration and limitations.
To reflect a device mode change, the host must pass the changed theme global prop, and the app must update the root class. After setup, verify the light → dark → light transition on an actual host.
Overriding the Theme for Only Some Elements
The following applies to direct Crispy token references or Tailwind v3 usage. Also check the v4 limitations above.
When you want to apply a different theme to only a specific area, add the seed-color-mode-light-only or seed-color-mode-dark-only class to that element.
All child elements inside an overridden area use that theme's tokens through CSS custom property inheritance.
Comparison with Web
| Web (React) | Lynx | |
|---|---|---|
| Theme control method | data-* attribute selectors | CSS class names |
| Global theme setting | Apply data-seed-color-mode + data-seed-user-color-scheme attributes to <html> | Apply seed-user-color-scheme-* class to <page> |
| Theme override | data-seed-color-mode="light-only" or "dark-only" attribute | seed-color-mode-light-only or seed-color-mode-dark-only class |
| Token inheritance | CSS custom property inheritance | CSS custom property inheritance (same) |
| Theme setup method | Bundler plugin injects <script> | Set className directly via the getSeedClassName() function |