shadcn
shadcn component usage conventions
shadcn components used as-is, native look, semantic classes only.
MUST
- Use shadcn components as-is. Why: no override drift.
- Semantic Tailwind colors only —
text-foreground/text-muted-foreground/text-destructive,bg-primary/bg-muted/bg-destructive,text-primaryfor links. Why: theme-driven, dark-mode safe. cn()for conditional classes. Why: merge precedence + the only composition path.
NEVER
- Hardcode hex / palette colors in
classNameorstyle—text-red-500,bg-blue-500,text-green-500. Cost: bypasses theme. fd-*aliases (bg-fd-muted,text-fd-muted-foreground,bg-fd-primary). Cost: fumadocs internals; use the shadcn name.- Template literal for conditional className. Cost: no merge precedence; use
cn(). cva/ bareclsx/ baretwMerge. Cost: fragments the singlecn()composition path.
Examples
| Good | Bad |
|---|---|
cn('base', cond && 'on') | `base ${cond ? 'on' : ''}` |
cn('base', v === 'a' ? 'x' : 'y') | clsx('base', ...) / cva(...) |
bg-muted text-primary | bg-fd-muted text-blue-500 |
Pitfall
global.cssaliases--color-*→--color-fd-*via@theme inline, sobg-muted/text-primary/border-borderresolve to the same theme asfd-*— always use the shadcn name.- fumadocs’ own UI (sidebar/search/TOC) keeps
fd-*internally — that is library code, not yours.