Tailwind CSS Best Practices (v4.1)
Goal: Create modern, performant, and maintainable styles using Tailwind CSS v4 native features.
1. The v4 "Iron Laws" (ALWAYS FOLLOW)
- •CSS-First Config: NEVER create
tailwind.config.jsfor new projects. Use@theme { ... }in your CSS file. - •No PostCSS needed: Trust the Oxide engine. It handles imports and nesting natively.
- •OKLCH Colors: Always use
oklch()for custom colors. It is the new standard for digital color. - •No
@apply: Avoid@applyin CSS files unless wrapping a 3rd party library. Extract to React/Vue components instead.
2. v4.1 Feature Mandates
When the user asks for these features, use the Native v4.1 Utilities, not plugins or hacks:
| Feature | Legacy / Hack (REJECT) | v4.1 Native (USE) |
|---|---|---|
| Text Shadow | drop-shadow, custom plugins | text-shadow-sm, text-shadow-blue-500 |
| Masking | style="mask-image:..." | mask-linear, mask-radial |
| Coloured Shadow | shadow-[rgba...] | drop-shadow-indigo-500, shadow-red-500 |
3. Layout & Responsivity
- •Container Queries First: If a component is reusable, use
@containeron the parent and@md:on the child. DO NOT use viewport breakpoints (md:) for internal component logic. - •Mobile-First: Never use
sm:to define the default state. Default is mobile.- •❌
sm:w-full md:w-1/2 - •✅
w-full md:w-1/2
- •❌
4. Anti-Patterns to Correct
If you see these, refactor them immediately:
- •Hex Codes:
bg-[#1da1f2]-> Define semantic--color-brandin@theme. - •Arbitrary Values:
p-[13px]-> Use the closest scalep-3(0.75rem) orp-3.5(0.875rem). - •String Interpolation:
`bg-${color}-500`-> Full class namesbg-red-500(so Oxide can detect them).
Documentation Index
- •Architecture & v4.1 Features: Config, Performance, detailed feature list.
- •Layout Patterns: Flex, Grid, Bento, Container Queries.
- •Design Tokens: Typography, Colors, Animation.