This tutorial aims to introduce you to the best practices of using Tailwind CSS, a utility-first CSS framework. By the end of this tutorial, you will have a good understanding of how to use utility classes effectively and customize Tailwind CSS to your specific project needs.
You'll learn:
Prerequisites:
In a utility-first CSS, you build complex designs by combining small, single-purpose classes. It might seem tedious at first, but it's highly flexible and efficient.
<div class="text-center py-2 bg-blue-500 text-white">
Hello, Tailwind CSS!
</div>
Each class here serves a specific purpose: text-center
centers the text, py-2
adds vertical padding, bg-blue-500
sets a blue background, and text-white
makes the text white.
Tailwind is extremely customizable through the tailwind.config.js
file. You can customize anything: colors, fonts, breakpoints, and more.
module.exports = {
theme: {
extend: {
colors: {
'custom-blue': '#153e75',
},
fontFamily: {
'sans': ['Helvetica', 'Arial', 'sans-serif'],
},
},
},
variants: {},
plugins: [],
}
<div class="max-w-md mx-auto bg-white rounded-xl shadow-md overflow-hidden md:max-w-2xl">
<div class="md:flex">
<div class="md:flex-shrink-0">
<img class="h-48 w-full object-cover md:w-48" src="/img/store.jpg" alt="An image">
</div>
<div class="p-8">
<div class="uppercase tracking-wide text-sm text-indigo-500 font-semibold">Product name</div>
<p class="mt-2 text-gray-500">This is a wider card with supporting text below as a natural lead-in to additional content.</p>
</div>
</div>
</div>
module.exports = {
theme: {
extend: {
colors: {
'primary': '#5B21B6',
'secondary': '#9D174D',
},
fontFamily: {
'body': ['Nunito', 'sans-serif'],
},
},
},
variants: {},
plugins: [],
}
We've covered how to efficiently use utility classes and how to customize Tailwind CSS for your specific needs. Your next steps could be learning more about responsive design with Tailwind, or exploring more of its customization options.
Solutions:
javascript
module.exports = {
theme: {
extend: {
colors: {
'primary': '#FF6B6B',
'secondary': '#4ECDC4',
},
fontFamily: {
'body': ['Poppins', 'sans-serif'],
},
},
},
variants: {},
plugins: [],
}