Skip to main content
rule CX Codex

styling · maxtrigify — Claude Code rule: what it does, how to install

styling is a Claude Code rule that enforces Tailwind CSS patterns. Guides the agent to combine classes with tailwind-merge, clsx, and CVA.

Apache-2.0 ★ 141 updated 2026-11-17

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/styling.md
Open on GitHub

What styling does

The rule instructs coding assistants to merge Tailwind utilities via a shared cn helper that combines clsx and tailwind-merge. Without resolving conflicts through tailwind-merge, competing utility classes stay in the markup and break component styling.

Class composition must follow a strict order: base styling first, component variants second, state-driven styles third, and incoming className overrides last. When handling multi-state elements, the rule requires creating variant maps with class-variance-authority outside the render function and generating types via VariantProps.

Dynamic interpolation like string templates is disallowed because Tailwind cannot scan constructed utility names; instead, arbitrary dynamic values must pass via CSS custom properties in inline styles. The project must have clsx, tailwind-merge, and class-variance-authority installed to implement these code patterns.

What it helps with

  • Prevent Tailwind class conflicts during props merging
  • Structure component variant states with CVA
  • Pass dynamic runtime styles through CSS variables
  • Enforce consistent base, variant, and override class ordering

Example prompts for the agent

  • Create a Button component using CVA variants and the cn utility
  • Refactor this Card so consumer className props override default styles
  • Add state-dependent styles without generating dynamic Tailwind class strings

How to install styling

Manually: put the files in place

.claude/rules/styling.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about styling

How to install styling in Claude Code?

Save the rule text into .claude/rules/styling.md inside your project directory.

What does the styling rule do?

It directs the agent to structure Tailwind CSS components using tailwind-merge, clsx, and CVA with a four-tier class priority order.

What is required for styling to work?

Your repository needs the clsx, tailwind-merge, and class-variance-authority dependencies.

Source text

styling.md · Apache-2.0
---
title: Component Styling with Tailwind CSS
impact: HIGH
impactDescription: Predictable, maintainable styling patterns
tags: styling, tailwind, cn, clsx, tailwind-merge, cva, class-variance-authority
---

## Component Styling with Tailwind CSS

Use Tailwind CSS with intelligent class merging (`tailwind-merge`), conditional classes (`clsx`), and variant APIs (CVA).

### The `cn` Utility Function

```tsx
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}
```

**Why:** Without `tailwind-merge`, conflicting classes both apply. The `cn` utility resolves conflicts intelligently.

### Class Merging

**Incorrect:**

```tsx
// Without tailwind-merge, conflicting classes both apply
className = "bg-red-500 bg-blue-500"; // Both classes apply, causing conflicts
className = "px-4 py-2 px-8"; // Both px-4 and px-8 apply
```

**Correct:**

```tsx
twMerge("bg-red-500", "bg-blue-500"); // "bg-blue-500"
twMerge("px-4 py-2", "px-8"); // "py-2 px-8"
twMerge("text-sm", "text-lg"); // "text-lg"
```

### Component Pattern: Order Matters

Apply classes in this order:

1. **Base styles** (always applied)
2. **Variant styles** (based on props)
3. **Conditional styles** (based on state)
4. **User overrides** (className prop)

**Incorrect:**

```tsx
// Wrong order: user className comes before variants, preventing overrides
className={cn(className, variant === 'primary' && 'bg-blue-500')}
```

**Correct:**

```tsx
const Component = ({
  className,
  variant,
  isActive,
  ...props
}: ComponentProps) => {
  return (
    <div
      className={cn(
        "rounded-lg border bg-white shadow-sm", // 1. Base
        variant === "primary" && "bg-blue-500", // 2. Variants
        isActive && "ring-2 ring-blue-500", // 3. Conditionals
        className // 4. User overrides
      )}
      {...props}
    />
  );
};
```

### Conditional Classes with `clsx`

```tsx
cn("base", isActive && "active");
cn("base", { active: isActive, disabled: isDisabled });
cn(["base", isLarge ? "text-lg" : "text-sm"]);
```

### Class Variance Authority (CVA)

For components with multiple variants:

```tsx
import { cva, type VariantProps } from "class-variance-authority";

const buttonVariants = cva(
  "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium transition-all",
  {
    variants: {
      variant: {
        default: "bg-blue-500 text-white hover:bg-blue-600",
        destructive: "bg-red-500 text-white hover:bg-red-600",
        outline: "border border-gray-300 bg-transparent hover:bg-gray-50",
        ghost: "hover:bg-gray-100",
      },
      size: {
        default: "h-9 px-4 py-2",
        sm: "h-8 px-3 text-sm",
        lg: "h-10 px-6",
        icon: "h-9 w-9",
      },
    },
    defaultVariants: {
      variant: "default",
      size: "default",
    },
  }
);

type ButtonProps = React.ComponentProps<"button"> &
  VariantProps<typeof buttonVariants>;

export const Button = ({ className, variant, size, ...props }: ButtonProps) => {
  return (
    <button
      className={cn(buttonVariants({ variant, size }), className)}
      {...props}
    />
  );
};
```

**Key points:**

- Define CVA variants **outside** the component
- Use `VariantProps<typeof variants>` for TypeScript types
- Always merge with `className` prop using `cn`

### Best Practices

**1. Extract Repeated Patterns:**

```tsx
export const focusRing = 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500';
export const disabled = 'disabled:pointer-events-none disabled:opacity-50';

className={cn(focusRing, disabled, className)}
```

**2. Use CSS Variables for Dynamic Values:**

**Incorrect:**

```tsx
// Dynamic class generation (not detected by Tailwind)
<div className={`bg-[${dynamicColor}]`} />
```

**Correct:**

```tsx
// CSS variables
<div
  className="bg-[var(--color)]"
  style={{ "--color": dynamicColor } as React.CSSProperties}
/>
```

**3. Document Variants:**

```tsx
type ButtonProps = {
  /** The visual style @default "default" */
  variant?: "default" | "destructive" | "outline" | "ghost";
  /** The size @default "default" */
  size?: "sm" | "default" | "lg" | "icon";
};
```

### Common Patterns

**State-Based Styling:**

```tsx
<div
  className={cn(
    "transition-all",
    isOpen ? "opacity-100 translate-y-0" : "opacity-0 translate-y-4"
  )}
/>
```

**CVA with Additional Conditionals:**

```tsx
<div
  className={cn(
    baseVariants({ variant, size }),
    isActive && "ring-2 ring-blue-500",
    isDisabled && "opacity-50 cursor-not-allowed",
    className
  )}
/>
```

© maxtrigify · Apache-2.0 · maxtrigify/Otto

Similar IDE rules

All IDE rules for Frontend and UI →

styling by other authors comes first.

styling calesthio Rule for styling mobjects in ManimGL: fill, stroke, opacity, and visual effects. Use it when building animations and want consistent, reusable styling across objects. CX Codex +1 ★ 78,316repo stars styling Devin-AXIS Rule for consistent React component styling: semantic color tokens instead of raw Tailwind values, built-in component variants, conditional classes via cn(). Prevents improper Tailwind usage and ensures light and dark theme support. CX Codex +1 ★ 7,523repo stars ux-design-systems hoodini ux-design-systems guides the agent in structuring design tokens, building UI components, and configuring dark mode. Useful when creating a frontend component library. CX Codex +1 ★ 301repo stars ui-styling claudekit ui-styling — a skill that helps your agent build accessible interfaces with shadcn/ui and Tailwind CSS: components, themes, dark mode, responsive layouts and canvas design. CX Codex +1 52,100installs shadcn-ui existential-birds Teaches the agent shadcn/ui component patterns — CVA variants, compound components, data-slot attributes. Fires on Button, Card, Dialog, cn() and Radix primitives. CX Codex +1 358installs shadcn-code-review existential-birds shadcn-code-review audits React components built with shadcn/ui, Radix primitives, and Tailwind CSS. Catches CVA mistakes, broken asChild slots, and missing accessibility states. CX Codex +1 206installs tailwindcss-advanced-components JosiahSiegel The tailwindcss-advanced-components skill covers Tailwind CSS component variants with CVA, compound variants, and cn. Use it when building reusable React components in shadcn/ui-style projects. CX Codex +1 253installs styling-nativewind-v4-expo tristanmanchester styling-nativewind-v4-expo guides setup and troubleshooting for NativeWind v4 with Tailwind CSS v3 in Expo React Native projects. CX Codex +1 423installs

From the same set18

The whole set →
as-child as-child is a Claude Code rule for merging a component’s props and handlers into a custom child without an extra DOM wrapper. It applies to composable React triggers. CX Codex +1 ★ 141repo stars documentation documentation is a Claude Code rule that standardizes UI component documentation. It enforces consistent sections for props, runnable examples, and accessibility guidelines. CX Codex +1 ★ 141repo stars state state is a Claude Code rule for controlled and uncontrolled React component state. It applies while designing component APIs and state props. CX Codex +1 ★ 141repo stars accessibility accessibility is a Claude Code rule that enforces accessible frontend patterns. It triggers when generating UI components, dialogs, and navigation menus. CX Codex +1 ★ 141repo stars polymorphism polymorphism is a Claude Code rule for React components that keep their styles and behavior across element types. The as prop selects the rendered element. CX Codex +1 ★ 141repo stars definitions definitions is a Claude Code rule that classifies UI artifacts and keeps names consistent across primitives, components, blocks, templates, and patterns. CX Codex +1 ★ 141repo stars components-build components-build is a Claude Code skill for building, reviewing, and refactoring reusable React components with the components.build specification. It activates for work on component APIs, accessibility, styling, and TypeScript props. CX Codex +1 ★ 141repo stars otto-design otto-design is a Claude Code skill that enforces UI mockup creation in Paper before building SwiftUI views. It triggers on redesigns, mockups, or any visual changes to Otto surfaces. CX Codex +1 ★ 141repo stars

Project sponsors

Companies that keep this analytics open