--- name: tailwindcss description: "Utility-first CSS framework for rapid UI development. Responsive design, custom utilities, configuration, component composition. Trigger: When styling with Tailwind CSS utility classes, creating responsive designs, or configuring Tailwind." skills: - conventions - a11y - css - humanizer dependencies: tailwindcss: ">=3.0.0 <5.0.0" allowed-tools: - documentation-reader - web-search --- # Tailwind CSS Skill ## Overview Utility-first CSS framework for building custom designs with composable utility classes. ## Objective Enable developers to build responsive, maintainable UIs using Tailwind's utility classes and configuration system. --- ## When to Use Use this skill when: - Styling components with utility-first CSS - Creating responsive designs with Tailwind breakpoints - Configuring Tailwind theme (colors, spacing, typography) - Building custom utilities or plugins - Using JIT mode for performance Don't use this skill for: - Material-UI styling (use mui skill) - Plain CSS without Tailwind (use css skill) - Complex animations requiring custom CSS (use css skill) --- ## Critical Patterns ### ✅ REQUIRED: Use Utility Classes ```html ``` ### ✅ REQUIRED: Configure Theme in tailwind.config ```javascript // ✅ CORRECT: Extend theme module.exports = { theme: { extend: { colors: { brand: '#1976d2', }, }, }, }; // ❌ WRONG: Hardcoding hex colors in classes
// Use theme colors instead ``` ### ❌ NEVER: Overuse @apply ```css /* ❌ WRONG: Defeats utility-first purpose */ .btn { @apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded; } /* ✅ CORRECT: Use utilities directly in HTML */
``` tailwind.config.js: ```javascript module.exports = { content: ["./src/**/*.{astro,html,js,jsx,ts,tsx,vue,svelte}"], // ⚠️ CRITICAL darkMode: "class", // or 'media' theme: { extend: { colors: { brand: "#1976d2", }, }, }, }; ``` ### Dark Mode ```html
Content adapts to dark mode
``` ```javascript // Toggle dark mode document.documentElement.classList.toggle("dark"); ``` --- ## Edge Cases **Arbitrary values:** Use square brackets for one-off values: `w-[137px]`, `top-[117px]`. Avoid overuse—extend theme instead. **Specificity conflicts:** Tailwind utilities have same specificity. Order in HTML matters. Use `!` prefix for important: `!mt-0`. **Purge/content configuration:** Ensure all template paths are in `content` array or classes will be purged in production. **Third-party component styling:** Some libraries use inline styles that override Tailwind. Use `!important` sparingly or wrapper divs. **@layer directive:** Use `@layer components` for custom component styles, `@layer utilities` for custom utilities. Ensures proper ordering. --- ## References - https://tailwindcss.com/docs - https://tailwindcss.com/docs/configuration