Lynx

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.

import { root } from "@lynx-js/react";
import { getSeedClassName } from "@seed-design/lynx-react";

function Root() {
  return (
    <page className={getSeedClassName({ colorMode: "system" })}>
      <App />
    </page>
  );
}

root.render(<Root />);

getSeedClassName() returns seed-user-color-scheme-light or seed-user-color-scheme-dark class depending on the colorMode option.

colorMode Option

colorMode SettingDevice SettingApplied Theme Class
system (default)Light modeseed-user-color-scheme-light
systemDark modeseed-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 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:

/* 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.

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,
});
Content.tsx
import * as styles from "./Content.css";

export function Content() {
  return (
    <view className={styles.content}>
      <text className={styles.label}>Text that responds to the theme</text>
    </view>
  );
}

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.

// The color automatically changes according to the theme
<view className="bg-bg-layer-default">
  <text className="text-fg-neutral">Text that responds to the theme</text>
</view>

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.

function MyComponent() {
  return (
    <view>
      {/* Area that follows the current global theme */}
      <text>The global theme is applied</text>

      {/* Area where dark mode is forced */}
      <view className="seed-color-mode-dark-only">
        <text>Dark mode is forced</text>
      </view>

      {/* Area where light mode is forced */}
      <view className="seed-color-mode-light-only">
        <text>Light mode is forced</text>
      </view>
    </view>
  );
}

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 methoddata-* attribute selectorsCSS class names
Global theme settingApply data-seed-color-mode + data-seed-user-color-scheme attributes to <html>Apply seed-user-color-scheme-* class to <page>
Theme overridedata-seed-color-mode="light-only" or "dark-only" attributeseed-color-mode-light-only or seed-color-mode-dark-only class
Token inheritanceCSS custom property inheritanceCSS custom property inheritance (same)
Theme setup methodBundler plugin injects <script>Set className directly via the getSeedClassName() function

Table of contents