Advanced Tailwind CSS Guide with Examples
1. Responsive Design
Tailwind uses a mobile-first approach to responsive design.
Example:
<div class="text-base md:text-lg lg:text-xl">Responsive Text</div>
This will render:
- text-base on mobile
- text-lg on medium screens (>=768px)
- text-xl on large screens (>=1024px)
2. Customizing Theme
You can customize Tailwind via the tailwind.config.js file.
Example:
module.exports = {
theme: {
extend: {
colors: {
brand: '#5A67D8',
}
}
}
}
Use in HTML:
<div class="bg-brand text-white">Custom Brand Color</div>
3. Dark Mode Support
Tailwind supports dark mode using the 'dark:' prefix.
Example:
<div class="bg-white dark:bg-gray-800 text-black dark:text-white">
Dark mode ready!
</div>
Enable it by adding 'darkMode: "class"' to the config.
4. Grid Layout
Tailwind offers utility classes for building grid layouts.
Advanced Tailwind CSS Guide with Examples
Example:
<div class="grid grid-cols-3 gap-4">
<div class="col-span-1 bg-red-100">1</div>
<div class="col-span-2 bg-green-100">2</div>
</div>
This creates a 3-column layout with spacing.
5. Animations and Transitions
Tailwind provides classes for transition and animation effects.
Example:
<button class="transition ease-in-out duration-500 hover:scale-110">
Hover me
</button>
This will scale the button when hovered.