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.
| Package | Condition |
|---|---|
@lynx-js/rspeedy | 0.15.0 or later, Rsbuild 2 and Rspack 2 based version |
tailwindcss, @tailwindcss/postcss | 4.x |
postcss | 8.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.
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.
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
Import this CSS in the app entry.
@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
@layerremoves 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
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
tailwindcssplugin with the PostCSS configuration above. Also apply the Lynx post-processing. - Replace the
@tailwinddirectives with the CSS import above. It does not include web Preflight. - Match the
@sourcepath 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.
Typography
Crispy typography tokens are provided as component classes.
Layout
Use Tailwind's Flexbox utilities on native <view> elements.
Lynx Platform Notes
overflow: scrollis not supported. Use a<scroll-view>element if scrolling is needed.- The default value of
positionisrelative(unlike the web'sstatic). <list>+<list-item>are used for virtualized lists.item-keyis required.- The CSS
initial,inherit, andunsetkeywords are not supported. - The
insetshorthand is not usable as of Lynx 3.7. Write thetop,right,bottom,leftlonghand directly.