Skip to content

project rulesFrontendtailwind

Tailwind CSS Rules

Project rules for Tailwind CSS: design tokens in theme config, class ordering, component extraction, dark mode and limited arbitrary values.

npx workspacetemplates add tailwind-css-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file22 lines · 1.6 KBFile
# Project rules: Tailwind CSS

## Tokens
- Define colors, fonts, spacing extensions, radii and breakpoints once in the theme (`tailwind.config` or the `@theme` block in CSS). Name colors by role (`brand`, `surface`, `danger`), not by hue.
- Use only theme values. Allow an arbitrary value like `w-[37px]` only for a one-off layout need, and add a short comment; repeat it twice and it becomes a token.
- Never write raw hex or rgb in class names or inline styles.

## Classes
- Order classes consistently, by layout, box, typography, color, state. Enforce it with `prettier-plugin-tailwindcss` and do not sort by hand.
- Build mobile first: base classes for small screens, then `sm:`, `md:`, `lg:` for larger ones. Do not hide content with `hidden` at one size and re-show it at another when a layout change would do.
- Avoid `!important` modifiers and avoid `@apply` for anything but base element styles.

## Reuse
- Extract a component (React, Vue, Svelte or a partial) when markup repeats three times. Do not extract a class.
- Compose conditional classes with `clsx` or `tailwind-merge` so variants override cleanly. Never build class names by string concatenation, because the compiler cannot see them.

## Dark mode and state
- Use the `dark:` variant with one strategy for the whole project (class or media). Pair every color with its dark counterpart or use semantic tokens that switch.
- Use `focus-visible:` styles on everything interactive and keep text contrast at WCAG AA.

## Before finishing
- Run the formatter, the linter and a production build to confirm no classes were purged.

What it does

This file keeps Tailwind markup consistent across a project and across authors. Colors, spacing and type come from the theme, and long class lists are handled by components instead of copy and paste.

It also sets limits on escape hatches such as arbitrary values and important flags, so a stylesheet does not turn into a pile of one-off numbers.

Example

you › Add a pricing card component with a highlighted plan

agent › The agent uses theme colors and spacing, builds a Card component with a variant prop merged by tailwind-merge, adds dark: pairs and focus-visible rings, and avoids arbitrary values.

Questions

Why not build class names dynamically?
Tailwind finds classes by scanning source text. A name assembled at runtime never appears, so its styles are missing from the build.
Does it work with Tailwind 3 and 4?
Yes. Where the config lives differs by version, and the rule just says to keep tokens in one place.
  • .NET Blazor Rules

    Project rulescsharp

    Free
  • Angular Rules

    Project rulesangular

    Free
  • Astro Rules

    Project rulesastro

    Free
  • Electron Rules

    Project ruleselectron

    Free