Comprehensive best practices guide for shadcn/ui applications, maintained by the shadcn/ui community. Contains 58 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
Installing and configuring shadcn/ui in a project
Writing new shadcn/ui components or composing primitives
Implementing forms with React Hook Form and Zod validation
Building data tables or handling large dataset displays
Customizing themes or adding dark mode support
Reviewing code for accessibility compliance
Rule Categories by Priority
Priority
Category
Impact
Prefix
1
CLI & Project Setup
CRITICAL
setup-
2
Component Architecture
CRITICAL
arch-
3
Accessibility Preservation
CRITICAL
ally-
4
Styling & Theming
HIGH
style-
5
Form Patterns
HIGH
form-
6
Data Display
MEDIUM-HIGH
data-
7
Layout & Navigation
MEDIUM
layout-
8
Component Composition
MEDIUM
comp-
9
Performance Optimization
MEDIUM
perf-
10
State Management
LOW-MEDIUM
state-
Quick Reference
1. CLI & Project Setup (CRITICAL)
setup-components-json - Configure components.json before adding components
setup-path-aliases - Configure TypeScript path aliases to match components.json
setup-cn-utility - Create the cn utility before using components
setup-use-cli-not-copy - Use CLI to add components instead of copy-paste
setup-css-variables-theme - Enable CSS variables for consistent theming
setup-rsc-configuration - Set RSC flag based on framework support
2. Component Architecture (CRITICAL)
arch-use-asChild-for-custom-triggers - Use asChild prop for custom trigger elements
comp-create-reusable-form-fields - Extract reusable form field components
comp-use-slot-pattern-for-flexibility - Use slot pattern for flexible content
9. Performance Optimization (MEDIUM)
perf-lazy-load-heavy-components - Lazy load components over 50KB
perf-memoize-expensive-renders - Memoize list items and expensive components
perf-optimize-icon-imports - Use direct imports for Lucide icons
perf-avoid-unnecessary-rerenders-in-forms - Isolate form field watching
perf-debounce-search-inputs - Debounce search and filter inputs
10. State Management (LOW-MEDIUM)
state-prefer-uncontrolled-for-simple-inputs - Use uncontrolled for simple forms
state-lift-state-to-appropriate-level - Lift state to lowest common ancestor
state-use-controlled-dialog-state - Control dialogs for programmatic access
state-colocate-state-with-components - Keep state close to where it's used
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Full Compiled Document
For a single-file reference containing all rules, see AGENTS.md.
Reference Files
File
Description
AGENTS.md
Complete compiled guide with all rules
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: shadcn3description: shadcn/ui Community Best Practices4---5# shadcn/ui Community Best Practices67Comprehensive best practices guide for shadcn/ui applications, maintained by the shadcn/ui community. Contains 58 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.89## When to Apply1011Reference these guidelines when:12- Installing and configuring shadcn/ui in a project13- Writing new shadcn/ui components or composing primitives14- Implementing forms with React Hook Form and Zod validation15- Building data tables or handling large dataset displays16- Customizing themes or adding dark mode support17- Reviewing code for accessibility compliance1819## Rule Categories by Priority2021| Priority | Category | Impact | Prefix |22|----------|----------|--------|--------|23| 1 | CLI & Project Setup | CRITICAL | `setup-` |24| 2 | Component Architecture | CRITICAL | `arch-` |25| 3 | Accessibility Preservation | CRITICAL | `ally-` |26| 4 | Styling & Theming | HIGH | `style-` |27| 5 | Form Patterns | HIGH | `form-` |28| 6 | Data Display | MEDIUM-HIGH | `data-` |29| 7 | Layout & Navigation | MEDIUM | `layout-` |30| 8 | Component Composition | MEDIUM | `comp-` |31| 9 | Performance Optimization | MEDIUM | `perf-` |32| 10 | State Management | LOW-MEDIUM | `state-` |3334## Quick Reference3536### 1. CLI & Project Setup (CRITICAL)3738- [`setup-components-json`](references/setup-components-json.md) - Configure components.json before adding components39- [`setup-path-aliases`](references/setup-path-aliases.md) - Configure TypeScript path aliases to match components.json40- [`setup-cn-utility`](references/setup-cn-utility.md) - Create the cn utility before using components41- [`setup-use-cli-not-copy`](references/setup-use-cli-not-copy.md) - Use CLI to add components instead of copy-paste42- [`setup-css-variables-theme`](references/setup-css-variables-theme.md) - Enable CSS variables for consistent theming43- [`setup-rsc-configuration`](references/setup-rsc-configuration.md) - Set RSC flag based on framework support4445### 2. Component Architecture (CRITICAL)4647- [`arch-use-asChild-for-custom-triggers`](references/arch-use-asChild-for-custom-triggers.md) - Use asChild prop for custom trigger elements48- [`arch-preserve-radix-primitive-structure`](references/arch-preserve-radix-primitive-structure.md) - Maintain Radix compound component hierarchy49- [`arch-extend-variants-with-cva`](references/arch-extend-variants-with-cva.md) - Use Class Variance Authority for type-safe variants50- [`arch-use-cn-for-class-merging`](references/arch-use-cn-for-class-merging.md) - Use cn() utility for safe Tailwind class merging51- [`arch-forward-refs-for-composable-components`](references/arch-forward-refs-for-composable-components.md) - Forward refs for form and focus integration52- [`arch-isolate-component-variants`](references/arch-isolate-component-variants.md) - Separate base styles from variant-specific styles5354### 3. Accessibility Preservation (CRITICAL)5556- [`ally-preserve-aria-attributes`](references/ally-preserve-aria-attributes.md) - Keep Radix ARIA attributes intact57- [`ally-provide-sr-only-labels`](references/ally-provide-sr-only-labels.md) - Add screen reader labels for icon buttons58- [`ally-maintain-focus-management`](references/ally-maintain-focus-management.md) - Preserve focus trapping in modals59- [`ally-preserve-keyboard-navigation`](references/ally-preserve-keyboard-navigation.md) - Keep WAI-ARIA keyboard patterns60- [`ally-ensure-color-contrast`](references/ally-ensure-color-contrast.md) - Maintain WCAG color contrast ratios61- [`ally-dialog-title-required`](references/ally-dialog-title-required.md) - Always include DialogTitle for screen readers62- [`ally-form-field-labels`](references/ally-form-field-labels.md) - Associate labels with form controls63- [`ally-aria-invalid-errors`](references/ally-aria-invalid-errors.md) - Use aria-invalid for form error states64- [`ally-checkbox-label-association`](references/ally-checkbox-label-association.md) - Wrap Checkbox with Label for click target65- [`ally-focus-visible-styles`](references/ally-focus-visible-styles.md) - Preserve focus visible styles for keyboard navigation6667### 4. Styling & Theming (HIGH)6869- [`style-use-css-variables-for-theming`](references/style-use-css-variables-for-theming.md) - Use CSS variables for theme colors70- [`style-avoid-important-overrides`](references/style-avoid-important-overrides.md) - Never use !important for style overrides71- [`style-use-tailwind-theme-extend`](references/style-use-tailwind-theme-extend.md) - Extend Tailwind theme for design tokens72- [`style-consistent-spacing-scale`](references/style-consistent-spacing-scale.md) - Use consistent Tailwind spacing scale73- [`style-responsive-design-patterns`](references/style-responsive-design-patterns.md) - Apply mobile-first responsive design74- [`style-dark-mode-support`](references/style-dark-mode-support.md) - Support dark mode with CSS variables7576### 5. Form Patterns (HIGH)7778- [`form-use-react-hook-form-integration`](references/form-use-react-hook-form-integration.md) - Integrate with React Hook Form79- [`form-use-zod-for-schema-validation`](references/form-use-zod-for-schema-validation.md) - Use Zod for type-safe validation80- [`form-show-validation-errors-correctly`](references/form-show-validation-errors-correctly.md) - Show errors at appropriate times81- [`form-handle-async-validation`](references/form-handle-async-validation.md) - Debounce async validation calls82- [`form-reset-form-state-correctly`](references/form-reset-form-state-correctly.md) - Reset form state after submission8384### 6. Data Display (MEDIUM-HIGH)8586- [`data-use-tanstack-table-for-complex-tables`](references/data-use-tanstack-table-for-complex-tables.md) - Use TanStack Table for sorting/filtering87- [`data-virtualize-large-lists`](references/data-virtualize-large-lists.md) - Virtualize lists with 100+ items88- [`data-use-skeleton-loading-states`](references/data-use-skeleton-loading-states.md) - Use Skeleton for loading states89- [`data-paginate-server-side`](references/data-paginate-server-side.md) - Paginate large datasets server-side90- [`data-empty-states-with-guidance`](references/data-empty-states-with-guidance.md) - Provide actionable empty states9192### 7. Layout & Navigation (MEDIUM)9394- [`layout-sidebar-provider`](references/layout-sidebar-provider.md) - Wrap layout with SidebarProvider95- [`layout-sidebar-collapsible`](references/layout-sidebar-collapsible.md) - Configure sidebar collapsible behavior96- [`layout-sidebar-groups`](references/layout-sidebar-groups.md) - Organize sidebar navigation with groups97- [`layout-sheet-mobile-nav`](references/layout-sheet-mobile-nav.md) - Use Sheet for mobile navigation overlay98- [`layout-breadcrumb-navigation`](references/layout-breadcrumb-navigation.md) - Implement breadcrumbs for deep navigation99100### 8. Component Composition (MEDIUM)101102- [`comp-compose-with-compound-components`](references/comp-compose-with-compound-components.md) - Use compound component patterns103- [`comp-use-drawer-for-mobile-modals`](references/comp-use-drawer-for-mobile-modals.md) - Use Drawer on mobile devices104- [`comp-combine-command-with-popover`](references/comp-combine-command-with-popover.md) - Create searchable selects with Command105- [`comp-nest-dialogs-correctly`](references/comp-nest-dialogs-correctly.md) - Manage nested dialog focus correctly106- [`comp-create-reusable-form-fields`](references/comp-create-reusable-form-fields.md) - Extract reusable form field components107- [`comp-use-slot-pattern-for-flexibility`](references/comp-use-slot-pattern-for-flexibility.md) - Use slot pattern for flexible content108109### 9. Performance Optimization (MEDIUM)110111- [`perf-lazy-load-heavy-components`](references/perf-lazy-load-heavy-components.md) - Lazy load components over 50KB112- [`perf-memoize-expensive-renders`](references/perf-memoize-expensive-renders.md) - Memoize list items and expensive components113- [`perf-optimize-icon-imports`](references/perf-optimize-icon-imports.md) - Use direct imports for Lucide icons114- [`perf-avoid-unnecessary-rerenders-in-forms`](references/perf-avoid-unnecessary-rerenders-in-forms.md) - Isolate form field watching115- [`perf-debounce-search-inputs`](references/perf-debounce-search-inputs.md) - Debounce search and filter inputs116117### 10. State Management (LOW-MEDIUM)118119- [`state-prefer-uncontrolled-for-simple-inputs`](references/state-prefer-uncontrolled-for-simple-inputs.md) - Use uncontrolled for simple forms120- [`state-lift-state-to-appropriate-level`](references/state-lift-state-to-appropriate-level.md) - Lift state to lowest common ancestor121- [`state-use-controlled-dialog-state`](references/state-use-controlled-dialog-state.md) - Control dialogs for programmatic access122- [`state-colocate-state-with-components`](references/state-colocate-state-with-components.md) - Keep state close to where it's used123124## How to Use125126Read individual reference files for detailed explanations and code examples:127128- [Section definitions](references/_sections.md) - Category structure and impact levels129- [Rule template](assets/templates/_template.md) - Template for adding new rules130131## Full Compiled Document132133For a single-file reference containing all rules, see [AGENTS.md](AGENTS.md).134135## Reference Files136137| File | Description |138|------|-------------|139| [AGENTS.md](AGENTS.md) | Complete compiled guide with all rules |140| [references/_sections.md](references/_sections.md) | Category definitions and ordering |141| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |142| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/shadcn in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
shadcn/ui Community Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.