Tailwind CSS
Reuse Leaf UI colors, radii and spacing in Tailwind.
Quick setup
For a project with Tailwind installed, choose the configuration for your version. Versions 3.x and 4.x are supported; upgrade first if you use 2.x or earlier.
Tailwind CSS 4
Add one import to your CSS entry:
Tailwind CSS 3
Add the preset and adjust content to match your source directories:
Keep the Tailwind 3 directives in your CSS entry:
For an existing configuration, append the preset and keep your source paths and plugins.
Examples
Basic usage
After setup, use leaf- names in utilities to share styles with components:
Reuse your theme styles
Share colors, radii and spacing with components.
bg-leaf-surface sets the background, p-leaf-md sets padding, and rounded-leaf sets the radius. Standard Tailwind utilities and variants such as hover: and md: still work.
Follow the theme
Utilities inside ConfigProvider follow its regional theme. Turn on dark mode to see the panel and button change together:
Utilities and components share a theme
Backgrounds, text and borders change together.
Backgrounds, text and borders read the current region's variables without extra dark: classes. Color and density changes do not require rebuilding Tailwind. See Theming for more options.
Common design variables
Both versions use the same utility names and extend the theme while keeping Tailwind defaults.
Color names also work with border-*, ring-*, fill-* and similar utilities. Type size utilities include the theme line height.
Usage tips
- Opacity: Tailwind 4 supports
bg-leaf-primary/50. In Tailwind 3, these colors do not support/50,bg-opacity-*ortext-opacity-*; define translucent colors in application CSS. - Source scanning: Write complete class names such as
bg-leaf-primaryinstead of constructingbg-leaf-${color}. - Base styles: A CSS-only page with no Leaf UI component imports also needs
@ifhover/leaf-ui/styles.css. - Breakpoints:
sm:andmd:use your Tailwind configuration, independently of ConfigProvider breakpoints. Follow Tailwind 4's official browser support requirements. - Regions and overlays: Custom Portal content needs the intended theme scope too. Leaf UI overlays synchronize themes automatically. Configure component-specific variables through ConfigProvider.