Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Add, manage, and compose shadcn/ui components with correct patterns, styling, and CLI workflows.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/styling.md
1# Styling & Customization23See [customization.md](../customization.md) for theming, CSS variables, and adding custom colors.45## Contents67- Semantic colors8- Built-in variants first9- className for layout only10- No space-x-* / space-y-*11- Prefer size-* over w-* h-* when equal12- Prefer truncate shorthand13- No manual dark: color overrides14- Use cn() for conditional classes15- No manual z-index on overlay components1617---1819## Semantic colors2021**Incorrect:**2223```tsx24<div className="bg-blue-500 text-white">25<p className="text-gray-600">Secondary text</p>26</div>27```2829**Correct:**3031```tsx32<div className="bg-primary text-primary-foreground">33<p className="text-muted-foreground">Secondary text</p>34</div>35```3637---3839## No raw color values for status/state indicators4041For positive, negative, or status indicators, use Badge variants, semantic tokens like `text-destructive`, or define custom CSS variables — don't reach for raw Tailwind colors.4243**Incorrect:**4445```tsx46<span className="text-emerald-600">+20.1%</span>47<span className="text-green-500">Active</span>48<span className="text-red-600">-3.2%</span>49```5051**Correct:**5253```tsx54<Badge variant="secondary">+20.1%</Badge>55<Badge>Active</Badge>56<span className="text-destructive">-3.2%</span>57```5859If you need a success/positive color that doesn't exist as a semantic token, use a Badge variant or ask the user about adding a custom CSS variable to the theme (see [customization.md](../customization.md)).6061---6263## Built-in variants first6465**Incorrect:**6667```tsx68<Button className="border border-input bg-transparent hover:bg-accent">69Click me70</Button>71```7273**Correct:**7475```tsx76<Button variant="outline">Click me</Button>77```7879---8081## className for layout only8283Use `className` for layout (e.g. `max-w-md`, `mx-auto`, `mt-4`), **not** for overriding component colors or typography. To change colors, use semantic tokens, built-in variants, or CSS variables.8485**Incorrect:**8687```tsx88<Card className="bg-blue-100 text-blue-900 font-bold">89<CardContent>Dashboard</CardContent>90</Card>91```9293**Correct:**9495```tsx96<Card className="max-w-md mx-auto">97<CardContent>Dashboard</CardContent>98</Card>99```100101To customize a component's appearance, prefer these approaches in order:1021. **Built-in variants** — `variant="outline"`, `variant="destructive"`, etc.1032. **Semantic color tokens** — `bg-primary`, `text-muted-foreground`.1043. **CSS variables** — define custom colors in the global CSS file (see [customization.md](../customization.md)).105106---107108## No space-x-* / space-y-*109110Use `gap-*` instead. `space-y-4` → `flex flex-col gap-4`. `space-x-2` → `flex gap-2`.111112```tsx113<div className="flex flex-col gap-4">114<Input />115<Input />116<Button>Submit</Button>117</div>118```119120---121122## Prefer size-* over w-* h-* when equal123124`size-10` not `w-10 h-10`. Applies to icons, avatars, skeletons, etc.125126---127128## Prefer truncate shorthand129130`truncate` not `overflow-hidden text-ellipsis whitespace-nowrap`.131132---133134## No manual dark: color overrides135136Use semantic tokens — they handle light/dark via CSS variables. `bg-background text-foreground` not `bg-white dark:bg-gray-950`.137138---139140## Use cn() for conditional classes141142Use the `cn()` utility from the project for conditional or merged class names. Don't write manual ternaries in className strings.143144**Incorrect:**145146```tsx147<div className={`flex items-center ${isActive ? "bg-primary text-primary-foreground" : "bg-muted"}`}>148```149150**Correct:**151152```tsx153import { cn } from "@/lib/utils"154155<div className={cn("flex items-center", isActive ? "bg-primary text-primary-foreground" : "bg-muted")}>156```157158---159160## No manual z-index on overlay components161162`Dialog`, `Sheet`, `Drawer`, `AlertDialog`, `DropdownMenu`, `Popover`, `Tooltip`, `HoverCard` handle their own stacking. Never add `z-50` or `z-[999]`.163