Skip to content

Tailwind CSS v4 prompt

Rules that make your coding agent write Tailwind CSS 4.3 the way it works: configuration in CSS, v4 class names and variants, container queries, and clean migrations from v3.

What it makes your agent good at

Agents still write Tailwind v3: they create tailwind.config.js, add @tailwind directives, use bg-opacity and v3 shadow sizes, and build class names from strings. This prompt gives them v4 as it is: @import and @theme in CSS, @custom-variant and @utility, the renamed scales, new variants and container queries, and the upgrade path.

  1. Configuration in CSS@import tailwindcss, tokens in @theme and @theme inline, @custom-variant for dark mode, never a tailwind.config.js.
  2. v4 class namesshadow-xs, rounded-xs, outline-hidden, ring-3, bg-linear-to-r and opacity modifiers instead of the v3 names.
  3. Variants agents missnot-*, in-*, nth-*, starting:, data-* and aria-* variants, and @container queries for components.
  4. Values that compilebg-(--brand) for CSS variables, brackets for literals, complete class strings instead of built ones.
  5. Custom CSS, the v4 way@utility with --value() instead of @layer utilities, @reference in CSS modules and component style blocks.
  6. Migrations from v3The upgrade codemod first, then the fixes it can't make and a grep list of v3 leftovers.

The Tailwind CSS v4 rules

112 lines, current to Tailwind CSS 4.3. Last reviewed October 23, 2026. Plain Markdown, no front matter: each agent's is below.

Download

tailwind-v4.md

# Tailwind CSS v4

You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.

## Before you write code

- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.
- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.
- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.
- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.

## Setup

- One line replaces the three `@tailwind` directives: `@import "tailwindcss";`. Import other CSS (`@import "tw-animate-css";`) after it.
- Vite: `import tailwindcss from "@tailwindcss/vite"` and `plugins: [tailwindcss()]`. PostCSS: `plugins: { "@tailwindcss/postcss": {} }`. Imports and vendor prefixes are built in: remove `postcss-import` and `autoprefixer`.
- Sources are detected automatically (git-ignored and binary files are skipped). Add others with `@source "../../packages/ui/src";`, exclude with `@source not "./legacy";`, set the root with `@import "tailwindcss" source("../src");`, or turn detection off with `source(none)` and list every `@source`. Safelist with `@source inline("bg-red-{500,600}");`.
- Plugins load in CSS: `@plugin "@tailwindcss/typography";`.
- v4 needs Safari 16.4+, Chrome 111+ and Firefox 128+, and is not meant to run through Sass, Less or Stylus.

## Theme in CSS

```css
@import "tailwindcss";

@custom-variant dark (&:where(.dark, .dark *));

@theme {
  --font-display: "Inter Variable", sans-serif;
  --color-brand: oklch(0.62 0.19 259);
  --breakpoint-3xl: 120rem;
  --animate-fade-in: fade-in 0.2s ease-out;
  @keyframes fade-in {
    from { opacity: 0; }
  }
}

@theme inline {
  --color-background: var(--background);
  --color-foreground: var(--foreground);
}

:root { --background: oklch(1 0 0); --foreground: oklch(0.145 0 0); }
.dark { --background: oklch(0.145 0 0); --foreground: oklch(0.985 0 0); }
```

- Each namespace makes utilities: `--color-*` (bg, text, border, fill, ring…), `--font-*`, `--text-*` (with `--text-xl--line-height`), `--font-weight-*`, `--tracking-*`, `--leading-*`, `--breakpoint-*` (responsive variants), `--container-*` (container queries and `max-w-*`), `--radius-*`, `--shadow-*`, `--inset-shadow-*`, `--drop-shadow-*`, `--text-shadow-*`, `--blur-*`, `--ease-*`, `--animate-*`. `--spacing` is one base value: every multiple works (`w-17`, `mt-13`).
- Remove a default namespace with `--color-*: initial;` (or everything with `--*: initial;`) before defining your own.
- Use `@theme inline` when a token points at another variable, as semantic tokens switched by `.dark` do, so utilities read the variable where they are used. Write tokens as complete colors (`oklch(…)`) and use them as `var(--background)`; never wrap them in `hsl(var(--x))`.
- Theme variables are real CSS variables: in custom CSS write `var(--color-brand)`, `--spacing(4)` and `--alpha(var(--color-brand) / 50%)`, not `theme()`. Only tokens something uses are emitted; `@theme static` emits them all (for tokens read from JavaScript).

## Variants

- Dark mode follows `prefers-color-scheme` by default. For a class or attribute toggle, declare `@custom-variant dark (&:where(.dark, .dark *));` (or `[data-theme=dark]`) once.
- Define your own with `@custom-variant name (selector);` or the block form with `@slot`, and use any variant inside custom CSS with `@variant dark { … }`.
- Variants stack left to right like CSS: `*:first:pt-0` (v3 wrote `first:*:pt-0`).
- `hover:` applies only on devices that can hover. Use `not-*` (`not-last:`, `not-hover:`), `in-*` (an ancestor's state without a `group` class), `has-*`, `nth-*` (`nth-3:`, `nth-[2n+1]:`), `starting:` (`@starting-style` for enter transitions), `open:` (details, dialog and popovers), `inert:`, `user-invalid:`, `pointer-coarse:`, `noscript:`, `*:` (children) and `**:` (descendants).
- State from components: `data-open:` for a present attribute, `data-[state=open]:` or `data-[side=top]:` for a value, `aria-expanded:`, `aria-[sort=ascending]:`, and `group-data-open:` or `peer-invalid:` across elements.
- Container queries are built in: `@container` (or `@container/main`) on the parent, `@md:`, `@max-md:` or `@md/main:` on children. Prefer them for components that live in columns of any width.

## Utilities and values

- CSS variables in arbitrary values use parentheses: `bg-(--brand)`, `w-(--sidebar-width)`, `text-(length:--size)` with a type hint when ambiguous. Brackets are for literal values: `grid-cols-[1fr_auto]`, `bg-[#0b0b0b]`.
- Opacity is a modifier on the color: `bg-black/50`, `text-primary/80`, `bg-(--brand)/20`. `bg-opacity-*` and `text-opacity-*` no longer exist.
- Important goes at the end: `flex!`. The leading `!flex` still compiles but is the old form.
- Gradients: `bg-linear-to-r`, `bg-linear-45`, `bg-radial`, `bg-conic`, with interpolation like `bg-linear-to-r/oklch`.
- Renamed scales (v3 to v4): `shadow-sm` is `shadow-xs` and `shadow` is `shadow-sm`; the same shift applies to `rounded`, `blur` and `drop-shadow` (`rounded-sm` to `rounded-xs`, `rounded` to `rounded-sm`). v3's `outline-none` is v4's `outline-hidden` (invisible, but kept in forced-colors mode); v4's `outline-none` removes the outline everywhere. `ring` is 1px (`ring-3` is v3's default). `shrink-*`, `grow-*` and `text-ellipsis` replace `flex-shrink-*`, `flex-grow-*` and `overflow-ellipsis`.
- Defaults changed: borders and rings are `currentColor` (always give `border-*` and `ring-*` a color or token), buttons get `cursor: default` (add `cursor-pointer` where the design wants it), placeholders are the text color at 50%, and `container` has no `center` or `padding` options (customize it with `@utility container { … }`).
- Prefer `flex` or `grid` with `gap-*` to `space-*` and `divide-*`, whose selectors changed to `:not(:last-child)`.
- Use what v4 adds instead of custom CSS: `size-*`, logical spacing and insets (`ms-*`, `pe-*`, `start-*`, `mbs-*`, `pbe-*`, `inset-bs-*`), `text-shadow-*`, `mask-*`, `inset-shadow-*`, `inset-ring-*`, 3D transforms (`rotate-x-*`, `perspective-*`, `transform-3d`), `field-sizing-content`, `wrap-break-word`, `scheme-dark`, `scrollbar-thin`, `justify-center-safe`.

## Custom CSS

- Custom utilities use `@utility`, which makes them work with every variant and sort correctly. A functional one reads its value with `--value()`:

```css
@utility content-auto {
  content-visibility: auto;
}

@utility tab-* {
  tab-size: --value(integer);
}
```

- Element defaults go in `@layer base`, and classes that utilities must override (third-party widgets) in `@layer components`. Custom utilities in `@layer utilities` are v3: they get no variants.
- In CSS modules and Vue, Svelte or Astro `<style>` blocks, start with `@reference "../app.css";` (or `@reference "tailwindcss";`) so `@apply` and theme variables resolve without emitting a second copy of Tailwind.
- Keep `@apply` for markup you cannot put classes on (third-party HTML, Markdown output). Components belong in JSX or templates, with class strings there.

## Class names in components

- Write every class name in full in the source: the scanner reads files as text and never runs code. `bg-${color}-500` produces nothing; map props to complete strings (`{ danger: "bg-red-600", info: "bg-sky-600" }`) or variants with `cva` or `tailwind-variants`.
- Merge caller classes with `cn()` (`twMerge(clsx(…))`, tailwind-merge 3 for v4) so the last conflicting class wins; class order in the attribute does not decide it on its own.
- Use theme tokens (`bg-background`, `text-muted-foreground`, `bg-brand`) over raw palette colors in a themed project, and over hex values everywhere.

## Migrating from v3

- Run `npx @tailwindcss/upgrade` on a clean branch (Node 20 or later). It moves the config into CSS, updates dependencies and renames classes in templates. Then fix by hand what it cannot see: class names built from strings, JavaScript plugins, `theme()` calls and custom `@layer` rules.
- Delete `tailwind.config.js` once its values live in `@theme`, and replace `tailwindcss-animate` with `tw-animate-css`.
- Grep for leftovers: `@tailwind`, `bg-opacity-`, `flex-shrink-`, `outline-none`, bare `shadow`, `rounded` and `ring`, and `space-y-` on inline children.

## Do not

- Do not create `tailwind.config.js`, write `@tailwind` directives, or add `postcss-import` and `autoprefixer`.
- Do not build class names from strings, or reach for `@apply` to make component classes.
- Do not use v3 names (`bg-opacity-*`, `flex-grow`, `bg-gradient-to-*`, `overflow-ellipsis`) or assume v3 sizes for `shadow`, `rounded`, `blur` and `ring`.
- Do not write `hsl(var(--token))`, `theme(colors.x)` or hex values where a token exists.

## Before you finish

- Run the dev server or build and check the classes you added appear in the CSS. A class with no effect is usually misspelled, built from a string, or in a file outside the sources.
- Check every breakpoint and container size you touched, dark mode, and the keyboard focus styles.
- After a migration, compare key pages against v3 screenshots for borders, rings, shadows and radius.

9,619 characters, 1,294 words. Under Windsurf's 12,000-character limit for a rule, as every prompt here is.

Use it in your agent

The same rules, where your agent reads them. Each file has the front matter its agent needs, set to apply on every request.

Claude Code

A rule it loads every session

  1. Save it as .claude/rules/tailwind-v4.md in your project, front matter included, or run the install command.
  2. Claude Code loads every file in .claude/rules with your CLAUDE.md when a session starts.
  3. Prefer one file? Paste it into CLAUDE.md under its own heading instead.

.claude/rules/tailwind-v4.md

# Tailwind CSS v4You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.## Before you write code- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.## Setup…

Or let the shadcn CLI write this file: sign in (free) for your command.

Cursor

A project rule with front matter

  1. Save it as .cursor/rules/tailwind-v4.mdc, front matter included, or run the install command.
  2. alwaysApply: true adds it to every Agent request in this project.
  3. Check it under Cursor Settings, Rules, then commit the folder for your team.

.cursor/rules/tailwind-v4.mdc

---description: "Writing Tailwind CSS v4 classes or CSS: @theme tokens, variants, custom utilities, sources, dark mode and migrating from v3."alwaysApply: true---# Tailwind CSS v4You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.## Before you write code- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.## Setup…

Or let the shadcn CLI write this file: sign in (free) for your command.

Windsurf

A workspace rule for Cascade

  1. Save it as .windsurf/rules/tailwind-v4.md, or run the install command.
  2. trigger: always_on applies it to every Cascade request in this workspace.
  3. Windsurf reads up to 12,000 characters per rule; this one is 9,619.

.windsurf/rules/tailwind-v4.md

---trigger: always_on---# Tailwind CSS v4You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.## Before you write code- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.## Setup…

Or let the shadcn CLI write this file: sign in (free) for your command.

GitHub Copilot

Instructions for the repository

  1. Save it as .github/instructions/tailwind-v4.instructions.md, or run the install command.
  2. applyTo: "**" applies it to every request in this repository.
  3. Or paste it into .github/copilot-instructions.md, which Copilot reads for every request.

.github/instructions/tailwind-v4.instructions.md

---description: "Writing Tailwind CSS v4 classes or CSS: @theme tokens, variants, custom utilities, sources, dark mode and migrating from v3."applyTo: "**"---# Tailwind CSS v4You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.## Before you write code- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.## Setup…

Or let the shadcn CLI write this file: sign in (free) for your command.

Codex & AGENTS.md

The file most agents read

  1. Paste it into AGENTS.md at your project's root, under its own heading.
  2. Codex reads AGENTS.md before it starts work, and so do Cursor, Zed, Jules, Amp and Copilot's coding agent.
  3. A folder can have its own AGENTS.md: the one closest to the file being edited wins.

AGENTS.md

## Tailwind CSS v4You are working in a project styled with Tailwind CSS v4 (`tailwindcss` 4.x). Write code for the version in `package.json`, not the one in your training data: in v4 the configuration lives in CSS, and many v3 class names, directives and defaults changed or are gone.### Before you write code- Check `tailwindcss` in `package.json` and how it is built: `@tailwindcss/vite` in the Vite config, `@tailwindcss/postcss` in `postcss.config.mjs` (Next.js and other non-Vite builds), or `@tailwindcss/cli`.- Find the stylesheet with `@import "tailwindcss"`: it is the configuration. Read its `@theme`, `@custom-variant`, `@utility`, `@source` and `@plugin` rules before adding classes or tokens.- Look up default token names in `node_modules/tailwindcss/theme.css` (colors, spacing, radius, shadows, breakpoints) instead of guessing a class.- A `tailwind.config.js` in a v4 project is only read when the CSS says `@config`. Never create one.### Setup…

AGENTS.md is shared with your own instructions, so paste the rules in: the copy sets their headings a level down.

Rules teach it. The MCP equips it. With Pro, your agent installs every component, block and icon it needs, from a prompt.

Get Pro

Pricing

Give your agent the parts, with Pro

The prompts are free. Every Pro plan adds the MCP server, so your agent installs the components, blocks and icons it writes code around.

4.9/5 out of 5 · 150+ reviewsfrom 150+ founders and developers.

Billed once a year in USD. Cancel anytime.

Individual

For personal projects & open source

$32instead of $49/mo

$389 billed yearly

  • How many people can use the license.Seats: 1 seat
  • Client work, SaaS products and anything you charge for.Commercial use: Personal & open source only
  • Page sections in 56 categories, from heroes and pricing tables to dashboards and settings, on every framework and UI library, in your theme.Blocks: All 6,181 blocks
  • Complete Next.js sites for startups, SaaS, agencies and portfolios, every page designed, ready to ship.Templates: All 14 templates
  • Your AI agent searches, previews and installs any component, block, icon or DESIGN.md from a prompt: 22 tools in Claude Code, Cursor, VS Code and 35 more clients.MCP server: 38 AI clients
  • Buttons with motion and states of their own, from an arrow that slides in to a burst of confetti.Animated buttons: All 35 buttons
  • Typewriters, scrambles, counters and more, for headlines, labels and numbers.Text effects: All 97 effects
  • Animated backgrounds for heroes, sections and cards, from a soft aurora to a flock that flees the cursor. Most are pure CSS.Backgrounds: All 100 backgrounds
  • WebGPU shaders, from a slow aurora to a black hole, each drawing only while it's on screen.Shaders: All 100 shaders
  • One design and one theme on all four: the components, blocks and effects are built for each framework.Frameworks: React, Vue, Svelte, Solid
  • React on Base UI, Radix UI, React Aria or Ark UI: install the version for the library your project already uses. Vue, Svelte and Solid run on Ark UI.UI libraries: Base UI, Radix, Aria, Ark
  • From a button to a date picker, a color picker or a guided tour: accessible, typed in TypeScript, each with live demos.Components: All 174 components
  • Real-world patterns built from the components, in 53 galleries: forms, tables, menus, dialogs and more.Examples: All 1,103 examples
  • Area, bar, line, pie, radar and radial charts on TanStack Charts, on every framework. React also gets the Recharts originals.Charts: All 70 charts
  • Debounce, local storage, media queries and more: each hook is one typed file you own.React hooks: All 35 hooks
  • From 222 libraries, Lucide, Heroicons, Tabler and Material Symbols among them, as SVG or a React component in one command.Icons: 294k+ icons
  • Stripe, Linear, Apple and 497 more: a brand's colors, typography and components in one file your AI agent builds from.DESIGN.md files: All 500 brands
  • Restyle every component and block at once: 8 styles, 7 grays, 18 colors and 5 radii, shared as a shadcn preset code.Theme builder: 8 styles × 18 colors
  • Priority requests are answered first.Support: Standard

Team

Most popular

For freelancers, agencies & startups

$66instead of $99/mo

$789 billed yearly · ≈ $13/dev/mo

Everything in Individual, plus

  • How many people can use the license.Seats: Up to 5 seats
  • Client work, SaaS products and anything you charge for.Commercial use: Included
  • Priority requests are answered first.Support: Priority

Organization

For companies with larger teams

$132instead of $199/mo

$1,589 billed yearly

Everything in Team, plus

  • How many people can use the license.Seats: Unlimited seats
  • Secure checkout via Stripe
  • Code lives in your repo
  • Keep what you've shipped if you cancel
  • License terms

Tailwind CSS v4 prompt FAQ

What the Tailwind CSS v4 prompt covers and how to use it in your agent.

Where does Tailwind CSS v4 configuration go?

In CSS. The prompt has the agent read the stylesheet that imports tailwindcss and add tokens in @theme, variants with @custom-variant and utilities with @utility. A tailwind.config.js is only read when the CSS points to it with @config, so the agent never creates one.

When should Tailwind v4 tokens use @theme inline instead of @theme?

Use @theme inline when a token points at another variable, like --color-background: var(--background) for tokens that change under .dark. The utility then reads the variable where it is used, so theme switches work. Plain @theme is for literal values such as a brand color or a font.

How do I make Tailwind v4 dark mode follow a .dark class?

Declare @custom-variant dark (&:where(.dark, .dark *)) once in the main stylesheet. Without it, dark: follows the operating system's prefers-color-scheme. The prompt also has the agent prefer semantic tokens that switch under .dark to pairs of dark: color classes.

Why are classes from a package missing in Tailwind v4?

Detection is automatic and skips git-ignored files, so a component library in node_modules or another workspace package needs an @source line. The prompt also covers @source not, source(none) and @source inline for safelisting.

4.9 out of 5 from 150+ developers

Rules teach it. The MCP equips it.

Every component, block and icon, installed by your AI agent on your stack. The prompts stay free.

Get Pro
  • Cancel anytime
  • Keep what you've shipped