1. Configuration Extensibility
Tailwind's config system allows for powerful customization through the theme object. Avoid overriding default values, instead extend and modify them where necessary.
module.exports = {
theme: {
extend: {
colors: {
primary: '#3498db',
secondary: '#2ecc71'
},
spacing: {
128: '32rem'
}
}
}
}
2. Custom Class Prefixing
Use class prefixes to avoid naming conflicts in large projects. This pattern is especially useful for component-specific styles.
module.exports = {
prefix: 'tw-',
theme: {
colors: { ... }
}
}
3. Responsive Design Patterns
Leverage Tailwind's responsive utilities using the following best practices for consistent mobile-first design:
<div class="sm:text-lg md:text-xl lg:text-2xl">
Responsive text sizing
</div>
<div class="container mx-auto px-4">
Responsive containers
</div>
4. Theme Variants
Create reusable theme variants for consistent UI components. Combine with the @apply directive for cleaner CSS output:
.btn-primary {
@apply bg-primary text-white px-4 py-2 rounded shadow
}