I have a confession: for the first couple of years I wrote CSS professionally, I avoided Grid completely. Flexbox was my hammer, and every layout was a nail. Nested flex containers, negative margin hacks, flex-basis: 33.333%. I made it all work, sort of. Then I opened the TechHub dashboard I was building on an actual tablet and watched my carefully nested flexbox layout fold into something that looked like a ransom note.
That was the project that finally forced me to learn CSS Grid properly, through Tailwind's utilities. This post is more or less everything I wish someone had told me before I started.
Why Grid, and why through Tailwind
Flexbox is one-dimensional. It's brilliant for a navbar, a button group, or centering an icon next to text. But the moment you're arranging content in two dimensions, rows and columns that need to stay in sync, flexbox makes you fight for it.
Grid thinks in two dimensions natively. And Tailwind's grid utilities map almost one-to-one onto the CSS spec, so nothing you learn here is wasted. grid-cols-3 is just grid-template-columns: repeat(3, minmax(0, 1fr)) under the hood, so you can always drop back to raw CSS when you outgrow the utilities.
The core utilities you'll actually use
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"> <article class="rounded-xl border p-6">...</article> <article class="rounded-xl border p-6">...</article> <article class="rounded-xl border p-6">...</article> </div> This is the pattern behind maybe 70% of the layouts on TechHub: one column on mobile, two on tablet, three on desktop, with gap-6 doing the spacing work that used to need margin gymnastics.
The important mental shift: the gap belongs to the container, not the children. No more last:mr-0 hacks, no more space utilities breaking the moment items wrap.
Mobile first, always
Every Tailwind breakpoint prefix is min-width. grid-cols-1 md:grid-cols-2 means one column by default, two from 768px up. Write the phone layout as the unprefixed default and add columns as space appears.
The card grid (and where it broke)
TechHub has a projects page: a grid of cards with a thumbnail, title, tags and stats. My first version:
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4"> It looked great on my monitor. Then someone on a 1280px laptop said the cards looked squished. Four columns at lg gave each card barely 280px. The fix I settled on:
<div class="grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4"> auto-fill with minmax tells the browser: fit as many 280px-minimum columns as you can, then stretch them to fill what's left. No breakpoints at all.
One gotcha: auto-fit collapses empty tracks, so with only two cards on a wide screen they stretch enormously. auto-fill keeps the empty tracks, so cards stay a sane size. I got this backwards the first time and spent a while wondering why two lonely cards were each the width of a small country.
Spanning: the dashboard shell
The brief: a stats row, a big chart, a sidebar of recent activity, and a full-width table. With flexbox this would have been three nested containers. With Grid it's one:
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6"> <!-- stats row: full width, its own inner grid --> <div class="lg:col-span-3 grid grid-cols-2 lg:grid-cols-4 gap-4"> <StatCard /> <StatCard /> <StatCard /> <StatCard /> </div> <!-- chart takes 2/3, activity feed takes 1/3 --> <section class="lg:col-span-2">...chart...</section> <aside>...recent activity...</aside> <!-- table spans everything --> <section class="lg:col-span-3">...table...</section> </div> On mobile everything stacks in source order. At lg the spans kick in and it becomes the dashboard. One container, and the source order still makes sense for screen readers.
What I'd actually do
- Start with one column and add breakpoints only when the design actually breaks in the browser, not when you think it might.
- Use auto-fill + minmax for card grids, breakpoint columns for page shells. Content-driven sizing and design-driven sizing are different problems.
- Don't abandon flexbox. Grid for the page, flex for the components inside it.
- Go easy on arbitrary values.
gap-[13px]in a code review usually means the design hasn't been thought through. - Resize the browser slowly across the whole range. The bugs live between the breakpoints. My squished-card bug shipped because I only ever checked 375, 768 and 1440.
If you're flexboxing everything and quietly dreading two-dimensional layouts, pick one page and rebuild it with Grid. It'll feel awkward for about an hour, and then you'll wonder why you waited so long.
Originally published on the TechInnoLab blog. We're a small remote studio building web apps and SaaS dashboards for UK and EU businesses.