Mastering Tailwind CSS for Modern Web
Nov 20, 2024
Why I switched from Bootstrap to Tailwind CSS and haven't looked back. A deep dive into utility-first CSS.
Tailwind CSS has taken the world by storm. It’s a utility-first CSS framework packed with classes like flex, pt-4, text-center and rotate-90 that can be composed to build any design, directly in your markup.
Why Utility-First?
Traditionally, you might write CSS like this:
.chat-notification {
display: flex;
max-width: 24rem;
margin: 0 auto;
padding: 1.5rem;
border-radius: 0.5rem;
background-color: #fff;
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
With Tailwind, you write this:
<div class="p-6 max-w-sm mx-auto bg-white rounded-xl shadow-lg flex items-center space-x-4">
<div class="shrink-0">
<img class="h-12 w-12" src="/img/logo.svg" alt="ChitChat Logo">
</div>
<div>
<div class="text-xl font-medium text-black">ChitChat</div>
<p class="text-slate-500">You have a new message!</p>
</div>
</div>
It’s faster, easier to maintain, and the file size is tiny in production thanks to purging.