Your HTML doesn't have to be a minefield: tips for mastering Tailwind without dying in the attempt
Frontend · 18 Aug 2025 · Michael Quintero

Introduction
The first time you see an HTML block full of Tailwind classes, it’s normal to feel a little chill down your spine.
class="flex items-center justify-between p-4 bg-white rounded-lg shadow-md".
It looks like someone wrote a CSS manual right inside your HTML. Many give up here, but I promise you the key to mastering Tailwind isn’t the number of classes, it’s how you organize them.
Tailwind is incredibly powerful. It lets you build complex interfaces without writing a single line of CSS in a separate file. Today I’ll show you how to use utility classes to create code that’s readable, maintainable, and—most importantly—doesn’t look like a mess!
The first trick: Extracting components
This is the fundamental pillar. If a block of utility classes repeats, don’t copy and paste it. Turn it into a reusable Vue component.
Before (chaotic code):
<div class="flex items-center p-4 bg-white rounded-lg shadow-md">
<img src="..." class="w-12 h-12 rounded-full mr-4">
<div>
<h3 class="font-bold text-lg">User</h3>
<p class="text-sm text-gray-500">@example_user</p>
</div>
</div>
After (refactored into a component):
<template>
<div class="flex items-center p-4 bg-white rounded-lg shadow-md">
<img :src="user.avatar" class="w-12 h-12 rounded-full mr-4">
<div>
<h3 class="font-bold text-lg">{{ user.name }}</h3>
<p class="text-sm text-gray-500">{{ user.handle }}</p>
</div>
</div>
</template>
Now, your main HTML looks this clean:
<UserProfileCard :user="currentUser" />
The second trick: The @apply directive
For situations where a group of classes is used very often and you don’t want to create a component (or it doesn’t make sense),
you can use Tailwind’s @apply directive in your CSS files.
.btn-primary {
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded-full hover:bg-blue-700 transition-colors;
}
And your HTML looks much cleaner:
<button class="btn-primary">Click me</button>
Note: Use @apply sparingly. If you overuse it, you can lose the flexibility that makes Tailwind so powerful.
The third trick: Conventions and mental organization
While there’s no strict rule, ordering your classes helps you find them quickly. You can adopt a logical order, for example:
- Layout:
flex, grid, block - Sizing:
w-12, h-4, max-w-md - Spacing:
p-4, m-2, space-x-2 - Backgrounds:
bg-white, bg-gray-100 - Typography:
text-xl, font-bold, text-center - Borders:
border, rounded-lg - Effects:
shadow-md, opacity-50 - States:
hover:, focus:, dark:
Conclusion
Tailwind isn’t chaotic, it’s a blank canvas. With a little discipline and the right techniques, you can create robust interfaces without sacrificing code readability.
Next time you see a block of classes, think: “Can I extract this into a component?” I guarantee this simple shift will turn you into a Tailwind master.