Back to Guidelines
Engineering Style Guide

TailwindCSS Guide

Readability & Quality Standards

Team standards for writing clean, maintainable Tailwind. Improve readability, lower maintenance cost, and embrace v4 features.

v1.0.0 (baseline)Applies to: all frontend engineers
01

Layout & Spacing

Consistent spacing strategy across flow and grid layouts.

1.1

Ban margin abuse, embrace gap

Avoid separating adjacent siblings with margin on children. Flow and grid layouts should control spacing with gap-* on the parent to avoid margin overflow or collapse.

Bad
<!-- children force mb-4 -->
<div class="flex flex-col">
  <div class="mb-4">Item 1</div>
  <div class="mb-4">Item 2</div>
  <div>Item 3</div>
</div>
Good
<!-- parent defines gap-4 -->
<div class="flex flex-col gap-4">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>
Live demo
gap-4
Item 1
Item 2
Item 3
1.2

Use space utilities for non-flex/grid

In block-level lists where flex/grid is inconvenient, use space-y-* / space-x-* on the parent to handle spacing between children automatically.

Bad
<div class="block">
  <p class="mt-2">Paragraph 1</p>
  <p class="mt-2">Paragraph 2</p>
</div>
Good
<div class="space-y-2">
  <p>Paragraph 1</p>
  <p>Paragraph 2</p>
</div>
02

Zero Arbitrary Values

Align to the scale, avoid magic numbers and hardcoded colors.

2.1

No bracket hardcoding [...]

Avoid magic numbers like w-[13px] or p-[15px]. Align strictly to the Tailwind scale for a consistent design system. Define special system-level sizes in the theme.

Bad
<div class="w-[320px] p-[16px] text-[14px]">
  Card
</div>
Good
<div class="w-80 p-4 text-sm">
  Card
</div>
Live demo
16px
2.2

Colors & opacity via design tokens

Never hardcode hex values. Use semantic theme colors combined with the opacity slash syntax (e.g. /80) instead of rgba(...).

Bad
<div class="bg-[#0f172a] text-[rgba(255,255,255,0.8)]">
  Dark Block
</div>
Good
<div class="bg-slate-900 text-white/80">
  Dark Block
</div>
Live demo
text-white/80

bg-slate-900

03

Embrace v4 Features

Modern standards that ship with TailwindCSS v4.

3.1

CSS-first theming (@theme)

v4 drops the traditional tailwind.config.js. Theme extensions are declared in the CSS entry file with the @theme directive for a more direct configuration.

Legacy (v3) tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        brand: '#0284c7'
      }
    }
  }
}
v4 Standard (app.css)
@import "tailwindcss";

@theme {
  --color-brand: #0284c7;
  --font-display: "Inter", sans-serif;
}
3.2

Native transform & 3D syntax

In v4 you no longer need the explicit transform class — use transform utilities directly. It also natively supports rotate-x-*, perspective-* and other 3D utilities.

Redundant (v3)
<div class="transform scale-105 rotate-45"></div>
Concise (v4)
<div class="scale-105 rotate-45"></div>
Live demo
rotate-y-25
scale-100
v4 3D
3.3

Enhanced selectors & state modifiers

Leverage modern CSS: use has-*, group-has-* and container queries (@container) to replace complex JS logic or global media queries.

Relies on JS
<label className={isChecked
  ? "border-blue-500"
  : "border-gray-200"}>
  <input type="checkbox" onChange={...} />
</label>
v4 native selector
<label class="border-gray-200
  has-[:checked]:border-blue-500">
  <input type="checkbox" />
</label>
Live demo
Pure CSS: has-[:checked]:border-chart-1 — no JS state
04

Class Ordering & Formatting

The team uses prettier-plugin-tailwindcss for on-save sorting. When writing by hand, follow this logical hierarchy.

No.CategoryExamples
1Layoutcontainer block flex grid absolute
2Box Modelw-full h-12 gap-4 p-4 m-2
3Typographytext-base font-bold text-slate-800
4Visualsbg-white rounded-lg border shadow-md
5State & Modifiershover:bg-slate-50 focus:ring-2 dark:bg-slate-900

Team automation

Install the Tailwind CSS IntelliSense extension and enable prettier-plugin-tailwindcss. Run npm run lint:style before committing to auto-fix ordering and formatting issues.