# Theming URL: /lynx/getting-started/styling/theming Source: https://github.com/daangn/seed-design/blob/dev/docs/content/lynx/getting-started/styling/theming.mdx 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](/lynx/getting-started/styling/vanilla-extract) or [Tailwind CSS v4](/lynx/getting-started/styling/tailwind-css-4), 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 `` element using the `getSeedClassName()` function from `@seed-design/lynx-react`. ```tsx import { root } from "@lynx-js/react"; import { getSeedClassName } from "@seed-design/lynx-react"; function Root() { return ( ); } root.render(); ``` `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 `` element. Represents the currently resolved theme. - `seed-user-color-scheme-light`: Light mode is applied - `seed-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 mode - `seed-color-mode-dark-only`: Force the area to dark mode ## How It Works Crispy CSS applies appropriate color tokens through combinations of class names: ```css /* When light mode is applied */ :root, :root.seed-user-color-scheme-light, :root.seed-color-mode-light-only, .seed-color-mode-light-only { /* Light mode color tokens */ } /* When dark mode is applied */ :root.seed-user-color-scheme-dark, :root.seed-color-mode-dark-only, .seed-color-mode-dark-only { /* Dark mode color tokens */ } ``` - The `:root` selector 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-*-only` selector handles theme overrides in child elements. It includes selectors both with and without the `:root` prefix, 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. ```ts title="Content.css.ts" import { vars } from "@seed-design/lynx-css/vars"; import { style } from "@vanilla-extract/css"; export const content = style({ backgroundColor: vars.$color.bg.layerDefault, }); export const label = style({ color: vars.$color.fg.neutral, }); ``` ```tsx title="Content.tsx" import * as styles from "./Content.css"; export function Content() { return ( Text that responds to the theme ); } ``` See the [Vanilla Extract guide](/lynx/getting-started/styling/vanilla-extract) 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`. ```tsx // The color automatically changes according to the theme Text that responds to the theme ``` 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 ``. 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](/lynx/getting-started/styling/tailwind-css-4). 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. ```tsx function MyComponent() { return ( {/* Area that follows the current global theme */} The global theme is applied {/* Area where dark mode is forced */} Dark mode is forced {/* Area where light mode is forced */} Light mode is forced ); } ``` 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 `` | Apply `seed-user-color-scheme-*` class to `` | | 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 `