Developer cleaning up spaghetti code in an editor

shadcn/ui + AI: Prompts That Keep Components Consistent Across Pages

shadcn/ui + AI prompts solve the page-five problem: your first screen looks polished, then the agent invents a second Button radius, a third Card shadow, and typography that drifts from Geist to random Inter weights. shadcn is copy-paste components — consistency is prompt discipline, shared tokens, and reusable instruction blocks. This post gives copy-paste prompts that keep vibe-coded pages on one design system. Updated November 2026.

shadcn ui components in a code editor with AI prompt instructions for design consistency across pages
shadcn does not drift — unconstrained AI sessions do. Prompts are your design system enforcement layer.

Pair these prompts with AI prompts for UI generation for layout semantics and accessible UI prompts for a11y non-negotiables. Admin-heavy apps should also read designing admin dashboards with AI — same token rules, higher table density.

Table of contents

  1. Why components drift across pages
  2. Foundation prompt (paste once per project)
  3. Page build prompt template
  4. Copy-paste shadcn prompts
  5. Tokens and globals.css guardrails
  6. Cursor rules snippet
  7. Visual review checklist
  8. FAQ

Why components drift across pages

Each new chat session re-decides:

  • Which shadcn components to install (duplicate variants)
  • Spacing scale (Tailwind gap-4 vs gap-6 roulette)
  • Button hierarchy (default vs outline vs ghost inconsistency)
  • Form patterns (Label + Input vs raw placeholders)
  • Dark mode class usage without shared tokens

Fix: one foundation prompt in project docs, page prompts that reference it, and a rule file the IDE injects every session. Align with your roadmap design phase before scaling page count.

Foundation prompt (paste once per project)

PROJECT UI CONTRACT — shadcn/ui + Tailwind

Stack: Next.js App Router, shadcn/ui already initialized, lucide-react icons only.
Do NOT install new UI libraries. Do NOT add MUI, Chakra, or random CSS files.

Components: use only from @/components/ui/* and @/components/shared/* if present.
Install missing shadcn components via CLI — do not hand-roll duplicates.

Typography: page title = text-3xl font-semibold tracking-tight; section title = text-xl font-semibold; body = text-sm text-muted-foreground for secondary copy.

Spacing: section vertical = py-8 md:py-12; stack gap = gap-4; form field gap = gap-2; max content width = max-w-6xl mx-auto px-4.

Buttons: one primary (default variant) per visible section; secondary actions outline; destructive actions destructive variant with AlertDialog confirm.

Cards: use Card, CardHeader, CardTitle, CardDescription, CardContent — no custom div boxes with shadow-lg unless specified.

Forms: Form + FormField + FormItem + FormLabel + FormControl + FormMessage with zod resolver — no unlabeled inputs.

Colors: use CSS variables from globals.css — bg-background, text-foreground, muted, border, primary. No hex colors in className.

Dark mode: class strategy on html; test both themes. No hardcoded bg-white.

Accessibility: every input has label; icon buttons have aria-label; focus rings visible.

Before finishing: list components added and confirm no new color hex values introduced.

Save as UI_CONTRACT.md and @ mention in every UI task.

Page build prompt template

Build [PAGE NAME] at app/[route]/page.tsx.

Read UI_CONTRACT.md and follow exactly.

Purpose: [one sentence user goal]
Primary action: [button label and destination]
Sections: [bulleted list]
Data: [mock or real fields — names and types]

Use existing SiteHeader and PageContainer from @/components/shared if they exist.
Reuse patterns from app/(marketing)/pricing/page.tsx for section spacing if present — do not invent new layout grid.

Deliver: single page file plus any extracted components only into components/[feature]/ with shadcn primitives composed — no stylistic one-offs.

Copy-paste shadcn prompts

Prompt 1 — Marketing hero section

Add a marketing hero to app/page.tsx using shadcn Button, Badge optional.
Layout: centered max-w-3xl, title text-4xl md:text-5xl font-bold tracking-tight, subtitle text-lg text-muted-foreground, two buttons (primary default + secondary outline).
No gradient backgrounds. No stock illustration components. Spacing: pt-16 pb-12 gap-6.
Follow UI_CONTRACT.md. Do not change globals.css.

Prompt 2 — Settings form page

Create app/settings/profile/page.tsx — profile settings form.
Fields: displayName (string), email (read-only), bio (textarea max 280).
Use shadcn Form with zod schema, Input, Textarea, Button default submit.
Section in Card with CardHeader "Profile" and CardDescription one line helper text.
Save button aligned end of CardFooter. Toast on success via sonner if installed.
Server action or API route with zod validation — no client-only fake save.
UI_CONTRACT.md spacing and typography.

Prompt 3 — Data list with empty state

Build app/projects/page.tsx listing user projects.
Use shadcn Table inside Card — columns: name (link), status Badge, updatedAt relative.
Server fetch paginated. Empty state inside TableBody single row: muted text + outline Button "Create project".
Loading: Skeleton rows matching column count. No custom table HTML.
Status badges: map draft=secondary, active=default, archived=outline — constants in lib/project-status.ts.
UI_CONTRACT.md — no new badge colors.

Prompt 4 — Dialog and confirmation pattern

Implement delete project flow on app/projects/[id]/page.tsx.
Pattern: destructive Button opens AlertDialog (not custom modal div).
AlertDialogAction calls server action deleteProject(id) with loading state on action.
Cancel = AlertDialogCancel outline behavior.
Reuse this AlertDialog pattern for all destructive actions — extract ConfirmDialog to components/shared/ConfirmDialog.tsx composing shadcn AlertDialog.
Document in UI_CONTRACT.md comment block.

Prompt 5 — Dashboard stat row (restrained)

Add dashboard stats row to app/dashboard/page.tsx — maximum 3 KPI cards.
Each: Card, CardHeader with CardDescription metric name, CardContent text-2xl font-semibold tabular-nums.
No charts on this page. Grid: grid-cols-1 sm:grid-cols-3 gap-4.
Metrics provided as props or server data: [MRR, Active users, Open tickets] — placeholder ok.
UI_CONTRACT.md — match existing dashboard page padding if file exists.

Prompt 6 — Navigation shell consistency

Audit app/(app)/layout.tsx navigation.
Use shadcn NavigationMenu or Sidebar pattern already in repo — pick one, remove duplicate nav implementations.
Active route styling: bg-accent text-accent-foreground — no custom blue hex.
Mobile: Sheet component for menu — must trap focus and close on navigate.
Do not add second header component — consolidate into components/shared/AppShell.tsx.
List files deleted and merged. UI_CONTRACT.md compliance.
Consistent shadcn ui button and card components across multiple pages in a Next.js application
Six prompts above cover 80% of vibe-coded UI — reuse before inventing prompt seven.

Tokens and globals.css guardrails

Prompt when AI tries to tweak theme:

Update ONLY these semantic tokens in globals.css :root and .dark — primary, radius, font-sans.
Do not add new CSS variables without listing in UI_CONTRACT.md.
Do not change tailwind.config except extending fontFamily if needed.
After edit, show before/after token table in comment.

Lock radius globally — --radius: 0.5rem — so Card and Button stay aligned. See tooling choices — Cursor rules plus shadcn beat switching generators mid-project.

Cursor rules snippet

When editing UI in this repo:
- Read UI_CONTRACT.md first
- Only shadcn/ui from @/components/ui
- No inline hex colors; use semantic Tailwind tokens
- One primary Button per section
- Forms require FormLabel and zod
- Destructive actions require AlertDialog
- Match spacing: section py-8 md:py-12, gap-4 stacks

Visual review checklist

CheckPass
Button variantsSame hierarchy on all new pages
Card structureHeader/title/description pattern consistent
Form labelsNo placeholder-only fields
SpacingSections align when navigating sidebar routes
Dark modeNo white flash or unreadable muted text
Iconslucide only; consistent size w-4 h-4 inline

Before ship, run launch checklist mobile and a11y rows against new pages.

Advanced: composing shared wrappers

When prompts repeat, generate once:

  • PageHeader — title, description, action slot
  • EmptyState — icon, message, CTA
  • FormSection — Card wrapper with standard padding
Create components/shared/PageHeader.tsx accepting title, description, action ReactNode.
Use shadcn typography tokens from UI_CONTRACT.md. Replace duplicated headers on [list files] — no visual change intended, only DRY.

Prompt 7 — Pricing table with shadcn

Build app/(marketing)/pricing/page.tsx with three-tier pricing.
Use Card per tier, CardHeader with plan name and price text-4xl font-bold, CardContent feature list with Check icon lucide w-4 h-4 inline text-primary.
CTA: Button default on highlighted tier (Badge "Popular" on middle tier only), outline on others.
Grid: md:grid-cols-3 gap-6 max-w-5xl mx-auto. No comparison table unless specified — cards only.
Feature list from constants in lib/pricing-plans.ts — do not hardcode in JSX twice.
UI_CONTRACT.md — identical Card padding on all tiers.

Prompt 8 — Refactor drift cleanup

Audit all pages under app/ for UI drift against UI_CONTRACT.md.
List violations: hex colors, non-shadcn buttons, missing form labels, duplicate nav shells.
Refactor to shared components without changing copy or business logic.
Output markdown table: file, issue, fix applied.
Do not add new design patterns — normalize only.

Multi-app and monorepo notes

If marketing and app live in one repo, duplicate shadcn installs drift fastest. Prompt once:

Ensure single components/ui directory at repo root packages/ui or apps/web/components/ui — pick existing structure, delete duplicate button.tsx copies in apps/marketing, re-export from shared package. Update imports across repo. Run typecheck.

Shared UI package beats re-prompting every app surface. Align with deploy docs — both apps must resolve same tailwind config extends.

Testing UI consistency

  • Storybook optional — screenshot diff marketing + app dashboard Button variants
  • Playwright smoke: primary button visible on key routes uses same class list
  • ESLint rule banning hex in className via regex plugin where feasible

Consistency is regression-prone after AI refactors — one visual test catches radius drift early. Pair with tests for AI-generated code.

Prompt anti-patterns that cause drift

Bad promptResultFix
“Make it beautiful”Random gradientsReference UI_CONTRACT spacing and tokens
“Use shadcn”Mixes raw Tailwind cardsList allowed component paths
“Match Stripe”Unmaintainable cloneDescribe hierarchy not brand mimic
New chat per pageInconsistent shell@ UI_CONTRACT + existing page path
“Quick hack only here”Permanent debtExtract shared if used twice

When shadcn components update

shadcn CLI updates can shift default styles. Process:

  1. Update one primitive in branch — Button first
  2. Visual diff key pages in staging
  3. Run UI drift audit prompt (Prompt 8 above)
  4. Merge when checklist passes — not all components at once

Pin component versions in UI_CONTRACT when stabilizing for launch week — “do not run shadcn update without explicit task.”

FAQ

shadcn or Tailwind UI for AI projects?

shadcn — components live in repo; agents edit source directly. Tailwind UI snippets confuse copy boundaries.

Agent keeps installing duplicate buttons

Point to @/components/ui/button in prompt; add Cursor rule forbidding new button components.

How many prompts before a custom design system?

After five pages, extract wrappers — not before two pages or you over-architect.

Does this work with Lovable export?

Reconcile imports to shadcn paths first — run foundation prompt on exported tree; expect cleanup sprint.

Radix vs shadcn confusion in prompts?

Tell agent: “Use shadcn wrappers in components/ui — do not import @radix-ui directly except inside shadcn primitives.”

Can AI update tailwind.config safely?

Only via token prompt above — otherwise manual review; bad config breaks all pages.

Soft CTA: Paste the foundation prompt into your repo tonight, @ it on the next three pages, and run the visual checklist before screenshot season. Consistent shadcn beats a seventh hero variant — your users notice coherence even if they cannot name shadcn.

Related reading on Vibe Coding Engineer

Continue with the vibe coding roadmap, the 2026 starter stack, and the Month 2 reading list. Each guide is written for builders who want outcomes, not hype — Free Code Hustle style. Bookmark this page and ship the next thin slice before you open another tab of tool comparisons.

When you are ready for monetization and ops, pair this article with Month 3 hubs on payments, security, and production monitoring. The goal is a compounding library: every post should make the next deploy safer, faster, or more useful to a real user.

Leave a Reply

Your email address will not be published. Required fields are marked *