shadcn/ui Best Practices
Use this skill for shadcn/ui authoring, review, architecture decisions, UI cleanup, and modernization. Center the answer on the fact that shadcn/ui ships source code you own: prefer composition, semantic tokens, and maintainable project conventions over one-off styling hacks.
Use This Skill When
- Building or reviewing shadcn/ui interfaces, pages, forms, overlays, or feature UIs
- Deciding between existing shadcn primitives and custom markup
- Setting up or auditing
components.json, aliases, Tailwind v4 wiring, or theme tokens - Debugging broken composition, invalid states, trigger APIs, or over-customized styling
- Modernizing older shadcn patterns such as deprecated
toastusage or brittle color overrides - Organizing feature code around
components/ui, app-level feature components, and local state boundaries
Out Of Scope
- Registry publishing or MCP workflows unless the user's main problem is specifically about registry authoring
- Framework-specific deployment or routing details that are not materially affecting shadcn usage
- Replacing shadcn/ui with a different component system
If the problem is mostly about generic React state, data fetching, or router behavior, keep the shadcn portion focused on the UI boundary.
Working Style
- Identify whether the task is setup, review, authoring, debugging, or modernization.
- Prefer existing shadcn components and documented composition patterns before suggesting custom wrappers.
- Read only the relevant reference file(s) below instead of loading everything.
- Keep base-vs-radix API differences explicit when they affect correctness.
- Prefer semantic tokens, variants, and CSS variables over raw utility overrides.
- When reviewing code, separate concrete accessibility or composition bugs from optional polish.
Reference Map
references/setup-installation-and-project-context.md- Use for initialization choices,
components.json, aliases, monorepo notes, and when CLI context matters.
- Use for initialization choices,
references/composition-primitives-and-layout.md- Use for component selection, triggers, overlays, layout, grouping rules, and replacing custom markup with primitives.
references/forms-accessibility-and-validation.md- Use for
Field,FieldGroup,FieldSet, invalid states, controlled inputs, and structured form composition.
- Use for
references/styling-theming-and-tailwind-v4.md- Use for semantic tokens, OKLCH variables,
@theme inline, Tailwind v4 behavior, and controlled customization.
- Use for semantic tokens, OKLCH variables,
references/organization-state-and-review-checklist.md- Use for file organization, state boundaries, maintainability rules, and review-oriented anti-pattern detection.
Response Requirements
- Treat shadcn/ui as owned source code, not as an untouchable package API.
- Prefer current patterns over older or deprecated guidance.
- Name accessibility requirements explicitly for overlays, fields, and invalid states.
- Avoid assuming CLI-injected project context exists; use
components.jsononly when relevant to the user's setup. - When base and radix differ, name the difference instead of pretending one API fits both.
- Prefer TypeScript examples unless the user explicitly wants JavaScript.
Core Defaults
- Prefer existing shadcn components and documented composition before inventing styled
divalternatives. - Prefer full component composition such as
CardHeaderplusCardContent,DialogHeaderplusDialogTitle, and grouped item structures insideSelectGroup,DropdownMenuGroup, or similar parents. - Prefer
Field,FieldGroup,FieldSet,FieldLegend, andFieldErrorfor form structure instead of ad hoc spacing wrappers. - Prefer
data-invalidon the field container andaria-invalidon the control for invalid-state styling and accessibility. - Prefer
sonnerover the deprecatedtoastcomponent. - Prefer semantic tokens and built-in variants over raw palette utilities or manual dark-mode color overrides.
- Prefer
@theme inline, CSS variables, and OKLCH-based theming for Tailwind v4 projects. - Prefer
size-*,gap-*, andcn()over duplicated width-height pairs,space-*, or manual class string concatenation. - Prefer local component state for transient UI like open tabs, expanded rows, and modal state; only lift state when multiple surfaces genuinely need shared coordination.
- Prefer gradual customization of generated components over early, broad rewrites that make future updates hard.
Provenance
This skill is authored from the bundled shadcn documentation and examples.