Home › shadcn/ui › shadcn/ui component rules

shadcn/ui component rules

Cursor rules for shadcn/ui with Tailwind CSS v4 and Radix: adding, composing, and theming components.

Cursorshadcn/ui

How to use

Save this as .cursor/rules/shadcn.mdc in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

.cursor/rules/shadcn.mdcDownload  
---
description: shadcn/ui component conventions
globs: ["components/**/*.tsx","app/**/*.tsx","src/**/*.tsx"]
alwaysApply: false
---

# shadcn/ui

- Add components with the CLI: `npx shadcn@latest add <name>`. Don't hand-copy component source from the web.
- Generated files in `components/ui/` are owned by the project. Edit them only for project-wide changes; build features by composing them in `components/<feature>/`.
- Merge classes with the `cn()` helper from `lib/utils`. Accept a `className` prop and pass it last.
- Variants via `cva` inside the component, not by long conditional class strings at call sites.
- Theme via the CSS variables in the global stylesheet (`--background`, `--primary`, ...) with Tailwind v4 `@theme inline`. Use semantic classes (`bg-primary`, `text-muted-foreground`), not raw colors like `bg-zinc-900`.
- Dark mode by the `.dark` class variables; never duplicate `dark:` overrides per component when a token exists.
- Forms: `react-hook-form` + `zod` with the `Form`/`Field` components the project has installed.
- Keep Radix accessibility: `asChild` for custom triggers, `DialogTitle` on every dialog (visually hidden if needed), labels on inputs.
- Icons from `lucide-react` with `aria-hidden` when decorative.

## Don't
- Don't install a second UI kit (MUI, Chakra) alongside it.
- Don't remove `focus-visible` styles.

## Done when
Lint, typecheck and build pass and the component looks right in both light and dark mode.

More: all shadcn/ui rules · all Cursor rules

Related rules

Astro content site rules

Cursor rules for Astro 5 sites with content collections, islands, and zero-JS-by-default pages.

CursorAstro

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

Lit web components rules

Cursor rules for Lit 3 web components in TypeScript: reactive properties, templates, styles, events, and accessibility.

CursorLit / web components

Next.js 16 rules (Cache Components, proxy.ts)

Cursor rules for Next.js 16 App Router: Cache Components with "use cache", proxy.ts, async request APIs, Turbopack.

CursorNext.js

Next.js App Router (TypeScript) rules

Cursor project rules for Next.js 15 App Router apps with TypeScript, Server Components, and Tailwind.

CursorNext.js

Nuxt 3 + Vue rules

Cursor rules for Nuxt 3 / Vue 3 apps using the Composition API, script setup and Pinia.

CursorVue / Nuxt

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.