Layout is where Tailwind’s benefit is easiest to see. You can convert mechanically from the CSS property names you already know, so there’s almost nothing new to learn.
TipsFlexbox cheat sheetTo refresh Flexbox itself, the cheatsheet with live demosThe Flexbox lookup table
Write flex on the parent. That’s display: flex. Then add from here.
| Tailwind | Plain CSS |
|---|---|
flex | display: flex |
flex-col | flex-direction: column |
flex-row-reverse | flex-direction: row-reverse |
flex-wrap | flex-wrap: wrap |
justify-start | justify-content: flex-start |
justify-center | justify-content: center |
justify-end | justify-content: flex-end |
justify-between | justify-content: space-between |
justify-around | justify-content: space-around |
justify-evenly | justify-content: space-evenly |
items-start | align-items: flex-start |
items-center | align-items: center |
items-end | align-items: flex-end |
items-stretch | align-items: stretch |
gap-4 | gap: 1rem |
flex-1 | flex: 1 1 0% |
shrink-0 | flex-shrink: 0 |
self-end | align-self: flex-end |
order-first | order: -9999 |
justify-content became justify-, align-items became items-. The flex in flex-start drops off too, giving the short justify-start.
The Grid lookup table
| Tailwind | Plain CSS |
|---|---|
grid | display: grid |
grid-cols-3 | grid-template-columns: repeat(3, minmax(0, 1fr)) |
grid-cols-none | grid-template-columns: none |
grid-rows-2 | grid-template-rows: repeat(2, minmax(0, 1fr)) |
col-span-2 | grid-column: span 2 / span 2 |
col-span-full | grid-column: 1 / -1 |
row-span-2 | grid-row: span 2 / span 2 |
gap-4 | gap: 1rem |
gap-x-4 / gap-y-2 | column-gap / row-gap |
place-items-center | place-items: center |
grid-cols-3 means “three equal columns” by default. It’s plain CSS’s repeat(3, 1fr), so the usual card list is covered.
The classic recipes, side by side
Header: logo left, menu right
/* plain CSS */
.header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem;
}<!-- Tailwind -->
<header class="flex justify-between items-center p-4">
<p class="font-bold">Shima's page</p>
<nav class="flex gap-4">
<a href="#about">About</a>
<a href="#works">Work</a>
</nav>
</header>flex justify-between items-center—those three settle a header’s skeleton.A card list (three columns)
/* plain CSS */
.cards {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
}<!-- Tailwind -->
<div class="grid grid-cols-3 gap-4">
<div class="p-4 bg-white rounded-xl">1</div>
<div class="p-4 bg-white rounded-xl">2</div>
<div class="p-4 bg-white rounded-xl">3</div>
</div>Making that one column on phones is the next lesson.
Sidebar plus content
/* plain CSS */
.layout { display: flex; gap: 1.5rem; }
.sidebar { flex: 0 0 240px; }
.main { flex: 1; }<!-- Tailwind -->
<div class="flex gap-6">
<aside class="w-60 shrink-0">Sidebar</aside>
<main class="flex-1">Content</main>
</div>w-60 is 240px (60 × 4) and shrink-0 means “don’t shrink”—plain CSS’s flex: 0 0 240px split across two classes.
Dead centre
/* plain CSS */
.center {
display: grid;
place-items: center;
min-height: 100vh;
}<!-- Tailwind -->
<div class="grid place-items-center min-h-screen">
<p>Centre</p>
</div>min-h-screen is min-height: 100vh. Full screen height is h-screen or min-h-screen—both come up often enough to memorise.
Push just one item to the right
<div class="flex gap-4">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#" class="ml-auto">Log in</a>
</div>ml-auto is margin-left: auto. The plain-CSS trick of “auto on one side pushes it away” works exactly the same here.
Width and height classes
Just the ones layout work needs.
| Tailwind | Plain CSS |
|---|---|
w-full | width: 100% |
w-1/2 | width: 50% |
w-1/3 w-2/3 | width: 33.333% 66.667% |
w-60 | width: 15rem (240px) |
max-w-4xl | max-width: 56rem (896px) |
h-screen | height: 100vh |
min-h-screen | min-height: 100vh |
mx-auto | margin-left/right: auto |
Capping the content width and centring it—the thing every site does—is these two together.
<div class="max-w-4xl mx-auto px-4">
content here
</div>The same shape as plain CSS’s “max-width for the cap, margin-inline: auto for centring, padding for breathing room.”
Summary of this lesson
- It starts by writing
flexorgrid—on the parent, same as plain CSS justify-contentbecamejustify-,align-itemsbecameitems-—just shortergrid-cols-3is three equal columns, with overflow-resistantminmax(0, 1fr)by defaultmax-w-4xl mx-autois the go-to combination for capping and centring content- Small tricks like
ml-autoandshrink-0work on the same logic as plain CSS
Next we add the md: prefix to all of this and switch by screen width.