Lynx

Tailwind CSS 4

Guides PostCSS configuration and compatibility limitations for using Tailwind CSS v4 in Lynx.

Lynx official guide covers integration of v3 and @lynx-js/tailwind-preset. That preset is not compatible with v4. Rsbuild itself supports v4. The following configuration uses Crispy theme and Lynx post-processing without that preset. Existing v3 projects can maintain the Tailwind CSS 3 configuration.

Tailwind CSS v4 can be used with @seed-design/tailwind4-theme and Lynx PostCSS post-processing. The following is a configuration verified for color, typography, spacing, corners, and class replacement by status of basic Crispy utilities, and root theme switching. This does not mean full Tailwind v4 features or compatibility across all Lynx Engines.

Requirements and Installation

This guide is based on Rsbuild 2 and Rspack 2 configuration introduced in Rspeedy 0.15 or later.

PackageCondition
@lynx-js/rspeedy0.15.0 or later, Rsbuild 2 and Rspack 2 based version
tailwindcss, @tailwindcss/postcss4.x
postcss8.x

Use ReactLynx and React plugin versions compatible with your chosen Rspeedy. Refer to the Rspeedy upgrade guide for Node requirements and existing configuration changes. This criterion is the build environment to which the configuration below will be applied, and does not mean Tailwind 4 itself only works on Rsbuild 2.

npm install @seed-design/lynx-css @seed-design/tailwind4-theme tailwindcss@4 @tailwindcss/postcss@4 postcss@8

You don't need to pin to a specific Tailwind patch version. However, not all 4.x version Lynx compatibility has been verified, so verify the CSS post-processing and actual screens below after updating. Crispy tokens are provided via @seed-design/lynx-css/base.css and do not import web @seed-design/css.

postcss.config.js

Transform the generated CSS in OnceExit after Tailwind processing. This file is Lynx app only and should not be applied to web apps.

postcss.config.js
import tailwindcss from "@tailwindcss/postcss";

function lynxTailwindCompatibility() {
  return {
    postcssPlugin: "lynx-tailwind-compatibility",
    OnceExit(root) {
      root.walkRules((rule) => {
        // Transform only Tailwind theme variable declarations.
        // Find combinations of :root and :host regardless of whitespace and selector order.
        const selectors = rule.selectors;
        if (
          selectors.length === 2 &&
          selectors.includes(":root") &&
          selectors.includes(":host")
        ) {
          rule.selector = ":root";
        }
      });

      // Do not reconstruct layer order. Expand content at declared positions.
      const layers = [];
      root.walkAtRules("layer", (rule) => {
        layers.push(rule);
      });
      for (const rule of layers.reverse()) {
        if (rule.nodes) rule.replaceWith(rule.nodes);
        else rule.remove();
      }
    },
  };
}

export default {
  plugins: [tailwindcss(), lynxTailwindCompatibility()],
};

Tailwind v4 outputs @theme variables to :root, :host. :host is a selector for web Shadow DOM. In the verified Lynx compiler, the combined rule was removed with Unsupported selector ":host,:root" was removed during template encode warning, causing theme variables to disappear as well. Therefore, we preserve :root and variable declarations, excluding only :host. This code is not a tool that converts :host(...) or arbitrary Shadow DOM CSS into Lynx CSS.

CSS import

src/styles/global.css
@import "@seed-design/lynx-css/base.css";
@import "tailwindcss/theme.css" layer(theme);
@import "@seed-design/tailwind4-theme";
@import "tailwindcss/utilities.css" layer(utilities);

/* Traverses the src directory relative to this CSS file. */
@source "../";

Import this CSS in the app entry.

src/index.tsx
import "./styles/global.css";

@import "tailwindcss" also includes web Preflight, so we load theme and utilities separately as shown above. Adjust the @source path to match the CSS file location. Classes must be written as full strings, like selected ? "bg-bg-brand-solid" : "bg-bg-neutral-weak", so they can be detected at build time.

Limitations and Items to Check

  • This configuration does not use @lynx-js/tailwind-preset. Rsbuild's v4 support alone does not guarantee Lynx CSS compatibility.
  • Expanding @layer removes the priority between layers and the layer order of !important. The selector priority and declaration order of the remaining CSS applies instead. In particular, re-check the result if you use Crispy recipes and utilities together, or add external layered CSS. This post-processing is not a general cascade layer polyfill.
  • Use the Crispy theme on the root <page>. Overriding the theme in a sub-area can cause the color of the Tailwind v4 alias variable and a direct Crispy token reference to differ. See the theming guide.
  • Other Tailwind output such as @property, @supports, web-only selectors, units, and CSS functions is not transformed by this plugin. Check additional utilities such as shadow, ring, gradient, and transform on the target Engine when you use them.
  • Do not judge screen compatibility from a successful build alone. Verify color, text, spacing, state changes, and device theme switching on an actual host.

Upgrading from Tailwind CSS 3

First, check whether your project's build tools meet the requirements above.

1. Replace Packages

npm uninstall @seed-design/tailwind3-plugin
npm install @seed-design/lynx-css @seed-design/tailwind4-theme tailwindcss@4
npm install -D @tailwindcss/postcss@4 postcss@8

Use a version of @seed-design/lynx-css that matches the peer range of the theme package. If you're using @lynx-js/tailwind-preset, remove it from the configuration and dependencies.

2. Replace PostCSS and CSS

  • Replace the existing PostCSS tailwindcss plugin with the PostCSS configuration above. Also apply the Lynx post-processing.
  • Replace the @tailwind directives with the CSS import above. It does not include web Preflight.
  • Match the @source path to your app's source location, and import the global CSS in the app entry.

3. Migrate Existing Configuration

v4 does not automatically read tailwind.config.ts. If you only used the Crispy plugin and content, the theme import and @source above replace it. If you have custom configuration, migrate it to @theme, @utility, and @plugin, then remove the existing configuration file.

For utility changes outside of Crispy, see the Tailwind v4 upgrade guide.

4. Check the Screen

Verify color, typography, spacing, state changes, and root theme switching in both the dev server and the production bundle. Also check that styles are reflected without a server restart when a new class is added.

Color

Crispy color tokens are used with Tailwind's bg-, text-, and border- prefixes.

// Background color
<view className="bg-bg-layer-default" />
<view className="bg-bg-neutral-weak" />
<view className="bg-bg-brand-solid" />

// Text color
<text className="text-fg-neutral">Default text</text>
<text className="text-fg-brand">Brand text</text>
<text className="text-fg-critical">Error text</text>

// Border color
<view className="border border-stroke-neutral-muted" />

Typography

Crispy typography tokens are provided as component classes.

<text className="t1-regular">Smallest text</text>
<text className="t5-regular">Default body</text>
<text className="t5-bold">Bold body</text>
<text className="t7-bold">Large heading</text>
<text className="t10-bold">Largest heading</text>

Layout

Use Tailwind's Flexbox utilities on native <view> elements.

// Flex row (HStack)
<view className="flex flex-row gap-x2 items-center">
  <view className="bg-bg-brand-weak px-x3 py-x2 rounded-r2">
    <text>A</text>
  </view>
  <view className="bg-bg-brand-weak px-x3 py-x2 rounded-r2">
    <text>B</text>
  </view>
</view>

// Flex column (VStack)
<view className="flex flex-col gap-x2">
  <text className="t5-regular text-fg-neutral">Item 1</text>
  <text className="t5-regular text-fg-neutral">Item 2</text>
</view>

Lynx Platform Notes

  • overflow: scroll is not supported. Use a <scroll-view> element if scrolling is needed.
  • The default value of position is relative (unlike the web's static).
  • <list> + <list-item> are used for virtualized lists. item-key is required.
  • The CSS initial, inherit, and unset keywords are not supported.
  • The inset shorthand is not usable as of Lynx 3.7. Write the top, right, bottom, left longhand directly.

Table of contents