--- name: tailwind-expert description: "Expert guide for Tailwind CSS v4, CSS-first configuration, @theme customization, modern responsive design, and Modern Web Guidance / Panduan ahli untuk Tailwind CSS v4, konfigurasi CSS-first, kustomisasi @theme, dan desain responsif modern." author: "Roedy Rustam" version: "4.4.2" --- # Tailwind CSS Expert (v4 Edition) [English](#english) | [Bahasa Indonesia](#bahasa-indonesia) --- ## English ### Description Strict guidelines and best practices for Tailwind CSS v4. Enforces the CSS-first configuration model, `@theme` token definitions, dynamic utilities, and performance optimization via Lightning CSS. ### Trigger Conditions - Scaffold or configure a Tailwind CSS v4 project. - Migrate a codebase from Tailwind CSS v3 to v4. - Implement design tokens via `@theme`. - Apply 3D transforms, CSS container queries, or `field-sizing`. ## Orchestration & Integration Integrates tightly with the following skills: - **`modern-web-guidance`**: Query modern web platform best practices before implementing bespoke styles. - **`anti-slop`**: Enforces strict anti-slop rules on Tailwind usage (no arbitrary value hacks, accessible focus rings, zero div-soup, and no cliché AI gradients). - **`design-system-architect`**: Establishes core tokens mapped inside `@theme` and surface container tiers. - **`modern-css-native-expert`**: Pairs Tailwind utilities with pure native CSS anchor positioning, `@starting-style`, and View Transitions. - **`visual-ui-auditor`**: Audits rendered Tailwind UI against the 20-point visual quality rubric. - **`senior-frontend`**: Feeds modern CSS capabilities into Next.js/React component architecture. ### Execution Standards #### 1. CSS-First Architecture Do NOT create `tailwind.config.js`. Define all configuration inside CSS using the `@theme` directive. ```css /* app/globals.css */ @import "tailwindcss"; @theme { /* OKLCH Colors for wide-gamut displays */ --color-brand-50: oklch(97% 0.02 250); --color-brand-500: oklch(55% 0.2 250); /* Typography */ --font-sans: "Inter Variable", system-ui, sans-serif; /* Custom breakpoints */ --breakpoint-3xl: 112rem; } /* Register plugins */ @plugin "@tailwindcss/typography"; ``` #### 2. Advanced Utilities Utilize v4-native features instead of custom CSS where possible: - **3D Transforms**: Use `perspective-1000`, `rotate-x-12`, `transform-3d`, `backface-hidden`. - **Color Mix**: Use inline mixing: `text-[color-mix(in_oklch,blue_70%,white)]`. - **Container Queries**: Use `@container` on the parent, `@sm:grid-cols-2` on children. - **Auto-sizing**: Use `field-sizing-content` for dynamically sizing textareas. #### 3. Migration (v3 to v4) When upgrading older codebases: 1. Run `npx @tailwindcss/upgrade` automatically. 2. Manually verify `tailwind.config.js` logic is perfectly translated to `@theme` CSS variables. 3. Replace deprecated `addVariant` plugin code with `@variant` CSS directives: ```css @variant hocus (&:hover, &:focus); @variant dark (&:where(.dark, .dark *)); ``` #### 4. Performance Directives - **Zero Configuration**: Rely on v4's automatic content detection. Do not manually specify content paths. - **Specificity**: Use `@layer utilities` strictly when custom CSS requires Tailwind's specificity tier. - **No `@apply` Abuse**: Avoid `@apply` in loops or highly repeated components; use HTML utility classes to leverage Lightning CSS tree-shaking. #### 5. Bootstrap to Tailwind Migration Guide 1. **Analyze the Legacy Structure**: - Identify the version of Bootstrap being used. - Locate custom CSS files that override Bootstrap defaults. - Identify interactive components (modals, dropdowns, tooltips, tabs, carousels) that rely on Bootstrap's JavaScript or jQuery. 2. **Setup Modern Tools**: - Ensure **Tailwind CSS v4** is properly set up in the project (e.g., via CDN for simple projects, or PostCSS/Vite for build steps). - Inject **Alpine.js** via CDN or module bundler to handle interactivity. 3. **Migration Strategy**: - **Grid & Layout**: Convert Bootstrap grids (`container`, `row`, `col-*`) to Tailwind flexbox (`flex`, `flex-col`, `gap-*`) or CSS Grid (`grid`, `grid-cols-*`). - **Spacing & Typography**: Map Bootstrap spacing (`m-3`, `p-4`) to Tailwind spacing (`m-4`, `p-6`—noting scale differences). Map typography utilities (`text-center`, `font-weight-bold`) to Tailwind equivalents (`text-center`, `font-bold`). - **Colors**: Update Bootstrap semantic colors (`primary`, `success`, `danger`) to Tailwind color palettes (e.g., `blue-600`, `green-500`, `red-500`) or define custom themes in CSS variables for Tailwind v4. - **Components**: Rebuild Bootstrap components (cards, buttons, alerts, navbars) using Tailwind utility classes to match or improve the original design. 4. **Interactivity with Alpine.js**: - Remove jQuery and Bootstrap JS dependencies. - Replace interactive Bootstrap components with Alpine.js data and directives. - **Dropdowns**: Use `x-data="{ open: false }"` and `@click="open = !open"`. - **Modals**: Use Alpine.js to manage the open state and handle background overlays and click-away events (`@click.outside`). - **Tabs**: Manage active tab state with `x-data="{ tab: 'home' }"`. 5. **UI/UX Modernization & Skill Integration**: - Do NOT just do a 1:1 translation of Bootstrap classes. The goal is to elevate the design. - You MUST orchestrate and apply guidelines from other UI/UX skills (`design-system-architect`, `ui-ux-pro-max`, and `hig`). - Implement Human Interface Guidelines (HIG) principles: Hierarchy, Harmony, and Consistency. - Use vibrant colors, smooth micro-animations, glassmorphism (if appropriate), and modern typography to "WOW" the user. 6. **Quality Assurance**: - Verify that responsive design behaves correctly across breakpoints (`sm:`, `md:`, `lg:`). - Ensure interactive components (modals, dropdowns) feel premium with Alpine.js transitions (`x-transition`). #### 6. Sovereign Anti-Slop Directives for Tailwind v4 Enforces zero-tolerance code standards for utility-first styling: - **No Arbitrary Value Hacks**: Ban arbitrary values (e.g., `p-[13px]`, `w-[372px]`, `text-[15px]`) when canonical spacing or typography scales exist. If a custom dimension is truly needed, declare it once in `@theme` as a semantic CSS variable token. - **Accessible Focus Indicator Law**: Never use `focus:outline-none` alone. You MUST pair it with `focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-` or an explicit high-contrast focus indicator. - **Zero Div-Soup Wrapper Bloat**: Do not nest redundant layout wrappers (`
...
`). Leverage modern CSS grid and subgrid directly on semantic containers (`
`, `