mcpField
T
tailwind-v4-best-practices

tailwind-v4-best-practices

github.com/jenishshresthaDesign & UI082 installsUpdated 28w ago
Repository

About tailwind-v4-best-practices

A Tailwind CSS v4 skill for developers building maintainable, themeable interfaces. It covers design tokens, utility-class practices, configuration, and migration guidance.

Key features

  1. 01Semantic design tokens
  2. 02Utility-class conventions
  3. 03CSS-based @theme configuration
  4. 04OKLCH color guidance
  5. 05v3-to-v4 class renames
  6. 06Vite setup guidance

Use cases

  1. 01Creating a themeable design system
  2. 02Choosing utilities for components
  3. 03Configuring Tailwind CSS v4 with Vite
  4. 04Migrating class names from v3

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/jenishshrestha/ai-skills --skill tailwind-v4-best-practices

After installing, type/tailwind-v4-best-practicesin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

evals/
evals.json
references/
advanced-patterns.md
design-tokens.md
migration.md
theming.md

Details

From the project README

Tailwind CSS v4 Best Practices

Production-grade Tailwind CSS v4 with a focus on design system thinking, maintainability, and performance.

Core Principles

1. Design Tokens, Not Direct Colors

Use semantic tokens instead of Tailwind's default color palette. This enables theme switching without touching components.

<!-- ❌ Direct colors — breaks when you rebrand -->
<button class="bg-blue-500 text-white hover:bg-blue-600">
<span class="text-red-600">Error</span>

<!-- ✅ Semantic tokens — theme-aware -->
<button class="bg-primary text-primary-foreground hover:bg-primary-hover">
<span class="text-error">Error</span>
2. Semantic Utilities Over Arbitrary Values

Use the built-in scale. Reserve arbitrary values for true one-offs.

<!-- ❌ Arbitrary when a utility exists -->
<h1 class="text-[20px]">
<div class="p-[16px] gap-[24px]">

<!-- ✅ Use the scale -->
<h1 class="text-2xl">
<div class="p-4 gap-6">
3. Complete Class Names Only

Tailwind's compiler needs full class names at build time. Never construct them dynamically.

// ❌ Tailwind can't detect these
<div className={`bg-${color}-500`}>

// ✅ Complete class names or CSS variables
<div className={color === 'blue' ? 'bg-blue-500' : 'bg-red-500'}>
<div className="bg-[var(--dynamic-color)]">
4. Avoid @apply

Tailwind v4 discourages @apply. Use utility classes directly in templates, or use theme() in CSS when you need custom component classes.

/* ❌ v3 pattern */
.button { @apply px-4 py-2 bg-blue-500 text-white rounded; }

/* ✅ v4 — use theme() if you need CSS */
.button {
  padding-inline: theme(spacing.4);
  background-color: theme(colors.primary);
}

@theme Configuration

Tailwind v4 moves config from JavaScript to CSS. Define design tokens with @theme:

@import "tailwindcss";

@theme {
  /* Semantic colors using OKLCH */
  --color-primary: oklch(0.55 0.25 250);
  --color-primary-hover: oklch(0.50 0.25 250);
  --color-primary-foreground: oklch(0.98 0 0);

  --color-error: oklch(0.60 0.22 25);
  --color-success: oklch(0.65 0.18 145);

  /* Surface colors */
  --color-background: oklch(1.0 0 0);
  --color-foreground: oklch(0.20 0.01 250);
  --color-surface: oklch(0.98 0.01 250);
  --color-border: oklch(0.90 0.01 250);

  /* Typography */
  --font-family-heading: "Inter", sans-serif;
  --font-family-body: "Inter", sans-serif;
  --font-family-mono: "Fira Code", monospace;
}

For full token architecture (Primitive → Semantic → Component layers), see references/design-tokens.md.

OKLCH Colors

Tailwind v4 defaults to OKLCH for better perceptual uniformity.

oklch(lightness chroma hue / alpha)
  • Lightness: 0 (black) to 1 (white)
  • Chroma: 0 (gray) to ~0.4 (vivid)
  • Hue: 0-360 degrees
  • Alpha: 0-1 (optional)
--color-brand: oklch(0.55 0.25 270);      /* vivid purple */
--color-subtle: oklch(0.96 0.02 250);     /* muted gray */
--color-overlay: oklch(0.0 0 0 / 0.5);   /* translucent black */

v3 → v4 Class Name Renames

v3                     →  v4
───────────────────────────────
bg-gradient-to-r       →  bg-linear-to-r
bg-gradient-to-br      →  bg-linear-to-br
flex-shrink-0          →  shrink-0
flex-grow              →  grow
decoration-clone       →  box-decoration-clone
decoration-slice       →  box-decoration-slice

Run the automated upgrade: npx @tailwindcss/upgrade

Vite Setup (Fastest)

import tailwindcss from '@tailwindcss/vite'

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

v4 auto-detects content — no need to configure content paths. Unused utilities are tree-shaken automatically in production.

References

Load only what you need for the current task:

ReferenceLoad When
design-tokens.mdSetting up token architecture, component tokens, status color patterns
theming.mdDark mode, runtime theme switching, brand variants, user preference detection
advanced-patterns.mdAnimations, grid layouts, container queries, custom utilities, plugins, performance
migration.mdMigrating a project from Tailwind v3 to v4

Comments

Markdown supported