c/frontend › command
0votes

Cursor rules for Tailwind CSS

TemplateLow risk Tested
submitted by CommandVault editors to c/frontend · 1 use

A .cursor/rules/tailwind.mdc that keeps utility classes consistent, readable and on-brand.

Template · 3 variables
---
description: Tailwind CSS conventions
globs: ["**/*.tsx","**/*.jsx","**/*.vue","**/*.svelte","**/*.html"]
alwaysApply: false
---

# Tailwind CSS

- Use theme tokens from `{{tailwind_config_path}}` (colors, spacing, radius); no arbitrary values like `text-[#123456]` unless the design requires it.
- Mobile first: base classes for phones, then `sm:`, `md:`, `lg:`.
- Order classes: layout → box → typography → color → state (or rely on the Prettier Tailwind plugin).
- Extract repeated class groups (3+ uses) into a component, not `@apply`.
- Every interactive element gets visible `focus-visible:` styles.
- Dark mode via `{{dark_mode_strategy}}`; check contrast in both themes.

## When you change code
- Follow the patterns in the nearest existing file before inventing new ones.
- Add or update a test for behavior changes; run `{{test_command}}`.
- Keep diffs small; explain anything surprising in your reply.
0 commentsreport

Guide

What you get: The agent builds UI with your theme tokens (no arbitrary values), mobile-first breakpoints, dark: variants, visible focus styles and a test. Best for Frontend teams using Tailwind who want consistent, on-brand utility classes from agents..

Before you start

  • A Tailwind project with theme tokens (Tailwind v4: an @theme block in your CSS; v3: tailwind.config.js)
  • A test command (we used Vitest + Testing Library: npm test)
  • Cursor: .cursor/rules/tailwind.mdc. Claude Code/Codex: the same text in CLAUDE.md / AGENTS.md

Worked example (Nov 14, 2026, Claude Code 2.1.318 (claude-opus-5-5); Codex 0.151.0 (gpt-5.6-sol))

Input

Vite 8 + React 19 + Tailwind 4.3 with brand tokens in src/index.css (@theme) and a class-based dark variant, an existing Button with focus-visible styles. Task: a 3-plan pricing section with a highlighted 'most popular' plan, responsive and dark-mode ready.

Result

Claude Code: a PricingCard component reusing Button, `grid gap-8 md:grid-cols-3`, `dark:bg-white/5`, `border-brand-600`. Codex: cards rendered from a plans array in App.tsx with `ring-2 ring-brand-500` for the popular plan.

Not tested in Cursor or Copilot: the rule text was saved verbatim (front matter included) as CLAUDE.md for Claude Code and AGENTS.md for Codex, the files those agents load at startup, plus a copy at its normal path. Filled with tailwind_config_path='src/index.css (the @theme block...)' and dark_mode_strategy='the dark class on <html>...'; because the blanks sit inside backticks, these phrase values broke the Markdown formatting of those two lines. Re-run by us: tests, oxlint and vite build pass for both; no arbitrary [..] values; no @apply; buttons reuse the existing focus-visible styles; mobile-first md: breakpoints. Neither actually measured contrast.

How to check it worked

  • grep the diff for '-[' to catch arbitrary values
  • Tab through the page: every button and link should show a focus ring
  • Toggle the dark class and look at both themes

Common problems

  • Tailwind v4 has no config file: point the token rule at the CSS file with @theme
  • Long values in the blanks break formatting because the blanks are inside backticks
  • 'check contrast in both themes' isn't something agents can measure without a tool

How to add this Cursor rule

  1. Fill in the 3 blanks above; Copy puts your answers into the file.
  2. Save it in .cursor/rules/ with the .mdc extension (plain .md files there are ignored), e.g. .cursor/rules/nextjs.mdc.
  3. The front matter decides when it applies: alwaysApply: true for every chat, globs for matching files, or a description so Cursor applies it when relevant.
  4. Check it in Cursor's Rules settings, then ask something about a matching file and confirm the answer follows the rule.
  • {{tailwind_config_path}} Tailwind config path
  • {{dark_mode_strategy}} Dark mode strategy
  • {{test_command}} Test command

Checked against Cursor docs: rules.

More from c/frontend

See all of c/frontend →
0 comments

Log in to join the discussion.