New to Claude Skills? Learn how to install them →

prowler-cloud on GitHub

Tailwind CSS 4 Patterns

Free

Master Tailwind CSS with best practices and patterns.

Get this skill

Free · Opens the source repo

What Tailwind CSS 4 Patterns does

Tailwind CSS 4 Patterns is a skill designed to help developers and designers implement Tailwind CSS effectively by providing clear guidelines and best practices. This skill offers a structured approach to styling components using Tailwind, ensuring that users avoid common pitfalls such as using CSS variables in class names or hex colors. The included decision tree simplifies the styling process, allowing users to quickly determine the appropriate method for applying styles based on their specific requirements.

The skill emphasizes the importance of using Tailwind's semantic classes over custom values, which enhances consistency and maintainability in projects. It also introduces the cn() utility, which facilitates conditional styling and merging class names, making it easier to manage dynamic styles. Users will find practical examples for various scenarios, including flexbox, grid layouts, typography, and responsive design, ensuring they can apply Tailwind CSS effectively across different contexts.

This skill is particularly beneficial for teams working on large-scale applications where maintaining a consistent design language is crucial. By adhering to the outlined rules and patterns, developers can ensure that their code remains clean and efficient, reducing the likelihood of style conflicts and improving overall project quality. Tailwind CSS 4 Patterns serves as a valuable resource for anyone looking to enhance their Tailwind CSS skills and streamline their styling workflow.

When to use it

Use this skill when working on projects that utilize Tailwind CSS, especially for dynamic styling and when adhering to best practices is critical.

When not to use it

This skill may not be suitable for projects that do not use Tailwind CSS or for developers who prefer to use custom CSS methodologies.

What you can build with it

Dynamic Styling in React

Use this skill to implement dynamic styles in React components, ensuring you follow Tailwind's best practices.

Maintaining Design Consistency

Refer to the guidelines when working on large applications to maintain a consistent design language across your project.

Avoiding Common Pitfalls

Utilize the critical rules to avoid common mistakes in Tailwind CSS, such as using hex colors and CSS variables in class names.

How to install Tailwind CSS 4 Patterns

View source

1. Install with the skills CLI

npx skills add prowler-cloud/prowler/tailwind-4 --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by prowler-cloud

Styling Decision Tree

Tailwind class exists?  → className="..."
Dynamic value?          → style={{ width: `${x}%` }}
Conditional styles?     → cn("base", condition && "variant")
Static only?            → className="..." (no cn() needed)
Library can't use class?→ style prop with var() constants

Critical Rules

Never Use var() in className

// ❌ NEVER: var() in className
<div className="bg-[var(--color-primary)]" />
<div className="text-[var(--text-color)]" />

// ✅ ALWAYS: Use Tailwind semantic classes
<div className="bg-primary" />
<div className="text-slate-400" />

Never Use Hex Colors

// ❌ NEVER: Hex colors in className
<p className="text-[#ffffff]" />
<div className="bg-[#1e293b]" />

// ✅ ALWAYS: Use Tailwind color classes
<p className="text-white" />
<div className="bg-slate-800" />

The cn() Utility

import { clsx } from "clsx";
import { twMerge } from "tailwind-merge";

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

When to Use cn()

// ✅ Conditional classes
<div className={cn("base-class", isActive && "active-class")} />

// ✅ Merging with potential conflicts
<button className={cn("px-4 py-2", className)} />  // className might override

// ✅ Multiple conditions
<div className={cn(
  "rounded-lg border",
  variant === "primary" && "bg-blue-500 text-white",
  variant === "secondary" && "bg-gray-200 text-gray-800",
  disabled && "opacity-50 cursor-not-allowed"
)} />

When NOT to Use cn()

// ❌ Static classes - unnecessary wrapper
<div className={cn("flex items-center gap-2")} />

// ✅ Just use className directly
<div className="flex items-center gap-2" />

Style Constants for Charts/Libraries

When libraries don't accept className (like Recharts):

// ✅ Constants with var() - ONLY for library props
const CHART_COLORS = {
  primary: "var(--color-primary)",
  secondary: "var(--color-secondary)",
  text: "var(--color-text)",
  gridLine: "var(--color-border)",
};

// Usage with Recharts (can't use className)
<XAxis tick={{ fill: CHART_COLORS.text }} />
<CartesianGrid stroke={CHART_COLORS.gridLine} />

Dynamic Values

// ✅ style prop for truly dynamic values
<div style={{ width: `${percentage}%` }} />
<div style={{ opacity: isVisible ? 1 : 0 }} />

// ✅ CSS custom properties for theming
<div style={{ "--progress": `${value}%` } as React.CSSProperties} />

Common Patterns

Flexbox

<div className="flex items-center justify-between gap-4" />
<div className="flex flex-col gap-2" />
<div className="inline-flex items-center" />

Grid

<div className="grid grid-cols-3 gap-4" />
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6" />

Spacing

// Padding
<div className="p-4" />           // All sides
<div className="px-4 py-2" />     // Horizontal, vertical
<div className="pt-4 pb-2" />     // Top, bottom

// Margin
<div className="m-4" />
<div className="mx-auto" />       // Center horizontally
<div className="mt-8 mb-4" />

Typography

<h1 className="text-2xl font-bold text-white" />
<p className="text-sm text-slate-400" />
<span className="text-xs font-medium uppercase tracking-wide" />

Borders & Shadows

<div className="rounded-lg border border-slate-700" />
<div className="rounded-full shadow-lg" />
<div className="ring-2 ring-blue-500 ring-offset-2" />

States

<button className="hover:bg-blue-600 focus:ring-2 active:scale-95" />
<input className="focus:border-blue-500 focus:outline-none" />
<div className="group-hover:opacity-100" />

Responsive

<div className="w-full md:w-1/2 lg:w-1/3" />
<div className="hidden md:block" />
<div className="text-sm md:text-base lg:text-lg" />

Dark Mode

<div className="bg-white dark:bg-slate-900" />
<p className="text-gray-900 dark:text-white" />

Arbitrary Values (Escape Hatch)

// ✅ OK for one-off values not in design system
<div className="w-[327px]" />
<div className="top-[117px]" />
<div className="grid-cols-[1fr_2fr_1fr]" />

// ❌ Don't use for colors - use theme instead
<div className="bg-[#1e293b]" />  // NO

Frequently asked questions about Tailwind CSS 4 Patterns

Similar skills