--- description: Comprehensive guide for Tailwind CSS best practices, covering code organization, performance optimization, security considerations, and common pitfalls. This rule provides actionable guidance for developers to build scalable and maintainable Tailwind CSS projects. globs: *.html,*.js,*.jsx,*.ts,*.tsx,*.vue --- - Leverage Tailwind's PurgeCSS to remove unused styles in production. Configure `purge` in `tailwind.config.js` to specify files to scan for Tailwind classes. Example: javascript module.exports = { purge: ['./src/*.js,*.jsx,*.ts,*.tsx', './public/index.html'], darkMode: false, // or 'media' or 'class' theme: { extend: {}, }, variants: { extend: {}, }, plugins: [], } - Use Tailwind's Configuration File (`tailwind.config.js`) to customize the theme, colors, spacing, breakpoints, and other design tokens. This promotes consistency and maintainability across the project. Avoid hardcoding values directly in the HTML or components. - Adopt a Mobile-First Approach: Design for smaller screens first and then use Tailwind's responsive modifiers (e.g., `md:`, `lg:`) to adapt the layout and styles for larger screens. This improves the user experience on mobile devices and reduces the amount of CSS needed. - Utilize Tailwind UI or other component libraries built with Tailwind CSS to accelerate development and maintain a consistent design language. Customize the components as needed to fit the specific requirements of the project. Alternatively, create your own reusable components. - Optimize for Performance: Be mindful of the number of Tailwind classes used on each element. Consider using `@apply` in CSS or extracting common styles into custom CSS classes to reduce duplication and improve performance. Use `content` variants when needed instead of the `DEFAULT` to control when generated classes are added. For instance, use `content-[url(..)]` instead of `content-[url(..)]`. Configure the JIT mode for faster build times during development. - Stay Organized with Components: Break down the UI into smaller, reusable components. Use a consistent naming convention for components and Tailwind classes. Consider using a component library like Storybook to document and showcase the components. - Integrate with a Design System: Define a clear design system with consistent colors, typography, and spacing. Map the design system tokens to Tailwind's configuration file. This ensures that the UI is consistent and aligned with the brand guidelines. - Use semantic class names: While Tailwind promotes utility-first CSS, consider using semantic class names in conjunction with Tailwind classes to improve readability and maintainability. For example, instead of `