Skip to content
FramesField
Intermediate API / Coding Agent
Verified Dec 1, 2026

Design System Audit and Tailwind v4 Migration

What you’ll make

A clean, audited Tailwind CSS v4 semantic token architecture (tokens.css + @theme inline), zero hardcoded hexes in component markup, automatic light/dark mode parity, and verified 1440px/390px Playwright QA passes.

Eliminate hardcoded hex sprawl, broken mobile tables, and fragile dark mode across an existing Astro, React, or Next.js frontend in under 45 minutes: grep raw color leaks, consolidate a 3-tier CSS custom property contract inside Tailwind CSS v4 @theme inline, swap SVG strokes to currentColor, and gate every route at 1440px and 390px via Playwright MCP and an isolated UI Design Critic subagent.

Before you start
  • An existing Astro, React, Next.js, or Vite codebase using Tailwind CSS v4 (or migrating from raw CSS / Tailwind v3).
  • Claude Code, Cursor, or Codex installed with Figma MCP (optional) and Playwright Visual QA MCP configured.
  • Install Skill 32 (CSS Design Tokens & Tailwind v4) and Skill 35 (UI Design Critic Subagent) before starting.
Estimated cost
$0 API (uses existing coding-agent session)
Time needed
35 – 45 min
Jump to section (5)
  1. 01Why AI-built frontends accumulate visual debt so fast
  2. 02Step 1: Run the baseline leak scan
  3. 03Step 2: Consolidate a 3-tier token contract in Tailwind v4
  4. 04Step 3: Sweep components, SVGs, and media assets cleanly
  5. 05Step 4: Gate both light/dark and 1440px/390px via Playwright MCP + Subagent
Step-by-step overview
SIGNAL PATH READY Click any node or press “Step Through” to trace data flow from input plate to final deliverable.
01–04
4-Stage Automated Design System Audit & Tailwind v4 Token Migration
Official Demo · Privacy-Enhanced Player (Zero Cookies Until Click)

4-Stage Automated Design System Audit & Tailwind v4 Token Migration

Tailwind Labs (Official Tutorial) · youtube-nocookie.com
Frame 01 STEP 01 · AUDIT
Hex & CLS Baseline
Static Grep + DOM Check

Inventory every arbitrary bg-[#...], missing img dimensions, and raw SVG fill inside src/components and src/pages.

Frame 02 STEP 02 · TOKENS
3-Tier @theme Map
Primitive -> Semantic -> Utility

Consolidate surface, border, ink, and signal custom properties inside tokens.css bound via @theme inline.

Frame 03 STEP 03 · VERIFY
Playwright + UI Critic
1440px + 390px · WCAG AA

Capture desktop and mobile renders, confirm 0 console errors, 0 horizontal overflow, and >= 4.5:1 text contrast.

Combining static hex-leak scanning, 3-tier Tailwind v4 @theme inline tokens, and Playwright 1440px/390px visual checks prevents AI-generated CSS drift permanently.

Source: Tailwind Labs (Official Tutorial) Model: FIGMA MCP + TAILWIND V4 + PLAYWRIGHT MCP Verified Dec 1, 2026
Original source ↗

Why AI-built frontends accumulate visual debt so fast

Even experienced teams shipping rapidly with AI coding assistants quickly notice their stylesheets fragmenting after three or four sprints: one page uses bg-dr-paper, another uses bg-stone-50, a third invents text-dr-muted, and an inline SVG icon disappears completely when dark mode turns on. Once arbitrary colors and magic pixel widths scatter across 40 components, every redesign turns into a brittle find-and-replace exercise.

This workflow gives you a deterministic 45-minute cleanup loop that locks a 3-tier semantic token architecture in Tailwind CSS v4 and gates every future visual edit through Playwright MCP and an isolated UI Design Critic subagent.

Step 1: Run the baseline leak scan

Copy audit-design-tokens.sh from the box below and execute it at your project root. In five seconds, it exposes four real design-system leaks that standard TypeScript checks ignore:

  1. Arbitrary hex Tailwind utilities (bg-dr-paper, text-dr-muted, border-dr-text) that bypass your token system and break dark mode.
  2. Inline hex styles hidden inside JSX or Astro template strings.
  3. <img> elements lacking explicit width and height, which trigger Cumulative Layout Shift (CLS) on slower mobile connections.
  4. Hardcoded black SVG icon strokes (stroke="#000000") that vanish against dark surfaces instead of inheriting CSS currentColor.

Save the output count as your starting baseline—your target at the end of Step 4 is 0 leaks across all four checks.

Step 2: Consolidate a 3-tier token contract in Tailwind v4

Install Skill 32: CSS Design Tokens and Tailwind v4 Theme Skill (and Skill 03: Figma MCP Design-to-Code Sync if syncing directly from Figma Variables). Consolidate all color, border, typography, and radius decisions into one clean cascade:

Token TierWhere It LivesAllowed in Component JSX?Example
Tier 1: Primitive Scale:root raw palette blockNever--raw-stone-50: #F7F7F5;
Tier 2: Semantic Intent:root + [data-theme="dark"]Indirectly via Tier 3--surface-canvas: var(--raw-stone-50);
Tier 3: Tailwind v4 @theme inline@theme inline { ... }Yes (Exclusive API)class="bg-canvas text-ink border-hairline"

Verify that every muted foreground token (--ink-muted) paired against both --surface-canvas and --surface-card exceeds WCAG 2.1 AA contrast (>= 4.5:1) in light and dark modes before touching component markup.

Step 3: Sweep components, SVGs, and media assets cleanly

Refactor components directory by directory rather than rewriting your entire repository in one massive diff:

  • Replace raw color classes with semantic utilities: Map every off-white background to bg-canvas or bg-surface, every subtle border to border-hairline, every secondary paragraph to text-ink-muted, and every primary brand accent to text-signal / bg-signal.
  • Unify SVG icon ownership: Optimize generated or exported vector icons (such as brand sets produced in Recraft V4.1) using Skill 30: SVG Optimization and Brand Icon System Skill, removing flat background <rect> elements and switching monochrome strokes to currentColor.
  • Standardize raster media: Re-encode oversized raw PNG hero banners (such as high-res Black Forest Labs FLUX 3 Image 2K–4K renders) into responsive WebP/AVIF sets with exact numeric width and height dimensions via Skill 31: Sharp WebP, AVIF and Responsive Image Skill.
  • Guard mobile overflow: Wrap every data <table> and <pre> code block inside overflow-x-auto and add min-w-0 onto flex and grid children that contain long code strings or URLs.

Step 4: Gate both light/dark and 1440px/390px via Playwright MCP + Subagent

Never sign off a CSS migration solely on a clean npm run build. Start your local preview server (npm run dev or npm run preview) and wire Skill 26: Playwright Visual QA MCP Server alongside Skill 35: UI Design Critic and Accessibility Subagent.

Delegate your primary pages (/, /pricing, detail pages) to @ui-design-critic:

  1. Captures real rendered screenshots at 1440×900 desktop and 390×844 mobile (in both light and dark modes if supported).
  2. Asserts document.documentElement.scrollWidth <= window.innerWidth so zero horizontal scrollbar leaks onto mobile phones.
  3. Confirms 0 browser console errors, 0 failed image/font network responses (>= 400), visible keyboard :focus-visible outlines, and clean WCAG AA contrast.
  4. Re-runs audit-design-tokens.sh confirming 0 arbitrary hex utilities remain.

Pair this migration guide with Guide 10: AI Design-to-Code: Figma MCP, Tokens and Visual QA and Workflow 04: Figma Design to Production Astro Landing Section via MCP to keep every new section locked to your design system permanently.

Copy-paste template

One-Command Design System Leak Audit & Tailwind v4 Token Starter audit-design-tokens.sh
Run this read-only audit script at your project root to list every raw hex utility, missing image dimension, and hardcoded SVG stroke before migrating to Tailwind v4 semantic tokens.
#!/usr/bin/env bash
set -euo pipefail

echo "=== 1. Arbitrary Hex Utilities in Components & Pages (Target: 0) ==="
grep -rnE '(bg|text|border|fill|stroke)-\[#[0-9a-fA-F]{3,8}\]' src/components src/pages || echo "PASS: 0 arbitrary hex Tailwind classes found."

echo ""
echo "=== 2. Inline Hex Color Declarations Inside Markup (Target: 0) ==="
grep -rnE 'style="[^"]*#[0-9a-fA-F]{3,6}' src/components src/pages || echo "PASS: 0 inline hex styles found."

echo ""
echo "=== 3. Images Missing Explicit width= or height= (CLS Risk) ==="
grep -rn '<img ' src/components src/pages | grep -vE 'width=.*height=|height=.*width=' || echo "PASS: Every <img> carries explicit width & height."

echo ""
echo "=== 4. Raw SVG Icons with Hardcoded Black Strokes/Fills ==="
grep -rnE '(stroke|fill)="#(000|000000|111|111111)"' src/components public/images/icons 2>/dev/null || echo "PASS: No hardcoded black SVG icon fills detected."

Helpful prompts & skills for this workflow

Frequently Asked Questions

Why use @theme inline instead of @theme in Tailwind CSS v4?
Writing @theme { --color-canvas: #F7F7F5; } hardcodes static hex values into compiled utility classes, breaking runtime theme toggling. Writing @theme inline { --color-canvas: var(--surface-canvas); } binds Tailwind utilities directly to live CSS custom properties so toggling [data-theme='dark'] re-themes every component in one block.
Do I need Figma to run this design-system audit and migration?
No. If your team maintains Figma Variables, connecting Figma MCP lets your agent verify 1:1 token naming parity. If you do not have Figma, the audit script, Tailwind v4 token hierarchy, and Playwright visual QA loop still clean up any existing codebase.
How do I prevent coding agents from re-introducing hardcoded hexes in future PRs?
Keep Skill 32 installed in .claude/skills/ or .cursor/skills/, document your semantic token table inside AGENTS.md, and add the grep command from audit-design-tokens.sh into your npm run audit or GitHub Actions CI workflow.
Use this page in AI tools or notes
raw .md