---
name: frontend-tailwind-best-practices
description: Tailwind CSS patterns and conventions for frontend apps. Use when writing component styles, layouts, or working with CSS classes.
---
# Tailwind CSS Best Practices
Styling patterns and conventions for frontend applications. Contains 10 rules covering layout utilities, affordances, color schemes, responsive design, and className handling.
## When to Apply
Reference these guidelines when:
- Writing component styles with Tailwind
- Creating layouts (stacks, grids, centering)
- Handling responsive design
- Working with color schemes
- Merging className props
## Rules Summary
### Layout Utilities (CRITICAL)
#### layout-stack-utilities - @rules/layout-stack-utilities.md
Use custom stack utilities instead of flex classes.
```tsx
// Bad
// Good
```
Available utilities:
- `v-stack` - Vertical stack (flex column)
- `h-stack` - Horizontal stack (flex row)
- `v-stack-reverse` - Reversed vertical stack
- `h-stack-reverse` - Reversed horizontal stack
- `z-stack` - Overlapping stack (grid-based, centers children on top of each other)
- `center` - Center content both horizontally and vertically
- `spacer` - Flexible spacer that fills available space
- `circle` - Perfect circle with aspect-ratio 1/1
#### layout-prefer-gaps - @rules/layout-prefer-gaps.md
Use `gap-*` on parents instead of child margins.
```tsx
// Bad
// Good
```
#### layout-responsive-stacks - @rules/layout-responsive-stacks.md
Switch layout direction at breakpoints.
```tsx
// Mobile: vertical, Desktop: horizontal
...
// Mobile: horizontal, Desktop: vertical
```
### Color Schemes (CRITICAL)
#### color-schemes - @rules/color-schemes.md
Use class-based color schemes with a custom `dark` variant.
```tsx
Toggle
```
### className Handling (CRITICAL)
#### classname-cn-utility - @rules/classname-cn-utility.md
Always use `cn()` to merge classNames in components.
```tsx
import { cn } from "~/lib/cn";
function Button({ className, variant }: Props) {
return (
);
}
```
#### classname-prop-types - @rules/classname-prop-types.md
Use proper types for className props.
```tsx
import type { ClassName, ClassNameRecord } from "~/lib/cn";
// Single element
type Props = {
className?: ClassName;
};
// Multiple elements
type Props = {
className?: ClassNameRecord<"root" | "label" | "input">;
};
// Usage
;
```
### Affordances (HIGH)
#### affordance-classes - @rules/affordance-classes.md
Define element-agnostic visual patterns that compose with utilities.
```tsx
Choose file
```
### Responsive Design (MEDIUM)
#### responsive-breakpoints - @rules/responsive-breakpoints.md
Use responsive prefixes with Tailwind defaults.
```tsx
// Standard breakpoints (min-width)
// Show/hide with standard breakpoints
Desktop only
Mobile only
```
#### responsive-text - @rules/responsive-text.md
Scale text responsively.
```tsx
// Responsive font size