CLAUDE.md rules for Tailwind CSS v4 with CSS-first theme tokens, mobile-first layouts, class-based dark mode, visible focus styles and cva variants.
.claude/rules/claude-tailwind-css-expert.md. Downloaded files need to be placed in that repository path.---
paths:
- "**/*"
---
# Tailwind CSS Conventions
Applies to: markup and components styled with Tailwind CSS in this repository, plus the CSS entry file that configures Tailwind.
Version baseline: checked against Tailwind CSS 4.1. Check `package.json` and the CSS entry file. If the project is on v3 (with a `tailwind.config.js` and `@tailwind` directives), keep v3 syntax and class names.
## Configuration (v4)
- Tailwind v4 is configured in CSS: `@import "tailwindcss";` plus `@theme { ... }` for design tokens such as `--color-brand-500` and `--font-display`. Add tokens there instead of using arbitrary values repeatedly.
- A JavaScript config is only loaded when the CSS file references it with `@config`. Don't create one unless the project already uses it.
- Class names must appear as complete strings in source files. Never build them by concatenation (`` `bg-${color}-500` ``). Map variants to full class strings instead.
## Class order and formatting
- Don't hand-sort classes. If the project uses `prettier-plugin-tailwindcss`, let it sort them. Otherwise keep the order consistent with the surrounding code.
- Extract a component (or a `cva` variant set) once the same long class list repeats. Use `@apply` sparingly, only in CSS for third-party markup you can't add classes to.
## Responsive design
- Write mobile-first: unprefixed classes for the smallest screens, then `sm:`, `md:`, `lg:` overrides. Use container queries (`@container`, `@md:`) for components that depend on their container rather than the viewport.
```html
<div class="flex flex-col gap-4 p-4 sm:flex-row sm:gap-6 lg:gap-8 lg:p-8">
<aside class="w-full sm:w-64 lg:w-80">Sidebar</aside>
<main class="min-w-0 flex-1">Content</main>
</div>
```
## Dark mode
- By default, `dark:` follows the operating system (`prefers-color-scheme`). For a manual toggle, declare the variant once in CSS and toggle a `dark` class on `<html>`:
```css
@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
```
```html
<div class="border border-gray-200 bg-white text-gray-900 dark:border-gray-700 dark:bg-gray-900 dark:text-white">
<p class="text-gray-600 dark:text-gray-400">Muted text</p>
</div>
```
- Check contrast in both themes. Muted text still needs 4.5:1 against its background.
## Accessibility
- Don't remove focus indicators without a replacement. Prefer `focus-visible:` rings, and use `outline-hidden` (the v4 name for v3's `outline-none`) only together with a visible ring.
- Respect motion preferences with `motion-safe:`/`motion-reduce:` on animations and transitions.
## Component variants
```tsx
import { cva, type VariantProps } from 'class-variance-authority';
export const button = cva(
'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
primary: 'bg-blue-600 text-white hover:bg-blue-700 focus-visible:ring-blue-500',
secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 focus-visible:ring-gray-500',
ghost: 'hover:bg-gray-100 focus-visible:ring-gray-500',
},
size: {
sm: 'h-8 px-3 text-sm',
md: 'h-10 px-4',
lg: 'h-12 px-6 text-lg',
},
},
defaultVariants: { variant: 'primary', size: 'md' },
},
);
export type ButtonVariants = VariantProps<typeof button>;
```
- When callers can pass extra classes, merge them with the project's helper (often `tailwind-merge` via a `cn()` function) so conflicting utilities resolve predictably.
## Verify before finishing
- Build the CSS (`npm run build` or the dev server) and confirm no unknown-utility warnings.
- Check the changed UI at small and large widths, in light and dark mode, and with keyboard focus.
- Run the formatter if configured (`npx prettier --check .`).
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
Claude
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Claude Code styles components in a Tailwind CSS v4 project with this file loaded as a project rule scoped to markup and CSS files.
Add a dark-mode toggle that sets class="dark" on <html>, and fix Button.tsx, which uses `focus:outline-none focus:ring-2` and builds `bg-${color}-600` dynamically. Tailwind ^4.1, src/app.css starts with @import "tailwindcss".Illustrative; not a recorded model run. `@custom-variant dark (&:where(.dark, .dark *));` added to app.css; Button variants rewritten as complete class strings in a cva config (no template-built class names); focus styles use focus-visible:outline-hidden with a visible focus-visible:ring-2; dark: classes for surfaces and muted text with a note to check 4.5:1 contrast; no tailwind.config.js created; build and visual checks reported.
Claude Code loads persistent project instructions from CLAUDE.md files and from Markdown rules in .claude/rules/. Rules can be scoped to file paths with a paths frontmatter field, and CLAUDE.md can import other files with @path syntax. The rules in this directory are written as plain instruction prompts: in Claude Code, save them as CLAUDE.md or .claude/rules/ content; in Claude.ai or the Claude API, use the same text as project instructions or a system prompt instead.
.claude/rules/claude-tailwind-css-expert.mdStarting point, not a tested configuration for your repository. Loaded when Claude Code works with files matching paths. Review the instructions, adapt the file paths and run your project's existing checks.
---
paths:
- "**/*"
---
# Tailwind CSS Conventions
Applies to: markup and components styled with Tailwind CSS in this repository, plus the CSS entry file that configures Tailwind.
Version baseline: checked against Tailwind CSS 4.1. Check `package.json` and the CSS entry file. If the project is on v3 (with a `tailwind.config.js` and `@tailwind` directives), keep v3 syntax and class names.
## Configuration (v4)
- Tailwind v4 is configured in CSS: `@import "tailwindcss";` plus `@theme { ... }` for design tokens such as `--color-brand-500` and `--font-display`. Add tokens there instead of using arbitrary values repeatedly.
- A JavaScript config is only loaded when the CSS file references it with `@config`. Don't create one unless the project already uses it.
- Class names must appear as complete strings in source files. Never build them by concatenation (`` `bg-${color}-500` ``). Map variants to full class strings instead.
## Class order and formatting
- Don't hand-sort classes. If the project uses `prettier-plugin-tailwindcss`, let it sort them. Otherwise keep the order consistent with the surrounding code.
- Extract a component (or a `cva` variant set) once the same long class list repeats. Use `@apply` sparingly, only in CSS for third-party markup you can't add classes to.
## Responsive design
- Write mobile-first: unprefixed classes for the smallest screens, then `sm:`, `md:`, `lg:` overrides. Use container queries (`@container`, `@md:`) for components that depend on their container rather than the viewport.
```html
<div class="flex flex-col gap-4 p-4 sm:flex-row sm:gap-6 lg:gap-8 lg:p-8">
<aside class="w-full sm:w-64 lg:w-80">Sidebar</aside>
<main class="min-w-0 flex-1">Content</main>
</div>
```
## Dark mode
- By default, `dark:` follows the operating system (`prefers-color-scheme`). For a manual toggle, declare the variant once in CSS and toggle a `dark` class on `<html>`:
```css
@import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
```
```html
<div class="border border-gray-200 bg-white text-gray-900 dark:border-gray-700 dark:bg-gray-900 dark:text-white">
<p class="text-gray-600 dark:text-gray-400">Muted text</p>
</div>
```
- Check contrast in both themes. Muted text still needs 4.5:1 against its background.
## Accessibility
- Don't remove focus indicators without a replacement. Prefer `focus-visible:` rings, and use `outline-hidden` (the v4 name for v3's `outline-none`) only together with a visible ring.
- Respect motion preferences with `motion-safe:`/`motion-reduce:` on animations and transitions.
## Component variants
```tsx
import { cva, type VariantProps } from 'class-variance-authority';
export const button = cva(
'inline-flex items-center justify-center rounded-md font-medium transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
primary: 'bg-blue-600 text-white hover:bg-blue-700 focus-visible:ring-blue-500',
secondary: 'bg-gray-100 text-gray-900 hover:bg-gray-200 focus-visible:ring-gray-500',
ghost: 'hover:bg-gray-100 focus-visible:ring-gray-500',
},
size: {
sm: 'h-8 px-3 text-sm',
md: 'h-10 px-4',
lg: 'h-12 px-6 text-lg',
},
},
defaultVariants: { variant: 'primary', size: 'md' },
},
);
export type ButtonVariants = VariantProps<typeof button>;
```
- When callers can pass extra classes, merge them with the project's helper (often `tailwind-merge` via a `cn()` function) so conflicting utilities resolve predictably.
## Verify before finishing
- Build the CSS (`npm run build` or the dev server) and confirm no unknown-utility warnings.
- Check the changed UI at small and large widths, in light and dark mode, and with keyboard focus.
- Run the formatter if configured (`npx prettier --check .`).
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Imports with @path can nest up to four hops deep, according to the docs. Claude Code can read AGENTS.md as project instructions without extra configuration, but by default only when there is no CLAUDE.md in the working directory or above it. The docs list this behavior for version 2.1.277 and later and describe a setting (claude-md-and-agents-md) that loads both files. If you maintain AGENTS.md for other tools, you can also import it from CLAUDE.md with @AGENTS.md.
Documentation checked 2026-11-05: Claude Code docs: Manage Claude's memory
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.