Tailwind CSS Grid Guide: Layouts, Responsive Grids and Examples
September 28, 2026 | 11 min read | Tailwind CSS
By Syed · Frontend Engineer & Creator of UITweak
Flexbox is great for one-dimensional layouts, but the moment you need a real two-dimensional layout, cards in rows and columns, dashboards, galleries, CSS Grid is the right tool. Tailwind makes Grid genuinely pleasant with short utilities like grid-cols-3 and col-span-2. This guide covers the 20% of Grid you will use 80% of the time, plus the responsive and auto-fit patterns that make layouts feel professional.
Shortcut: design your grid visually in our free Tailwind Grid Builder and copy the classes in one click.
1. The Two Classes That Start Every Grid
Every grid needs a container and a column definition:
<div className="grid grid-cols-3 gap-4">
<div>Card 1</div>
<div>Card 2</div>
<div>Card 3</div>
<div>Card 4</div> {/* wraps to row 2 automatically */}
</div>grid: turns the element into a grid container (equivalent todisplay: grid).grid-cols-3: three equal columns. Tailwind supportsgrid-cols-1throughgrid-cols-12out of the box.gap-4: 1rem spacing between all rows and columns. Usegap-x-6 gap-y-2when horizontal and vertical spacing should differ.
2. Spanning: Make Items Cover Multiple Tracks
The featured-card pattern, one big card plus smaller ones, is just spanning:
<div className="grid grid-cols-3 gap-4">
<div className="col-span-2">Featured (2 columns wide)</div>
<div>Side card</div>
<div>Card</div>
<div>Card</div>
<div className="col-span-3">Full-width banner</div>
</div>col-span-2 means "occupy 2 columns", row-span-2 does the same vertically. Spans are relative to the column count, so col-span-3 inside grid-cols-3 is full width.
3. Responsive Grids: The Pattern You Will Use Everywhere
This single pattern handles most responsive layouts on the modern web:
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
{/* 1 column on mobile, 2 on tablets, 4 on desktop */}
</div>Mobile-first: start with the smallest screen (grid-cols-1), then add columns at larger breakpoints. Combine with responsive spans when the featured item should only span on desktop:
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div className="md:col-span-2">Featured on desktop, normal on mobile</div>
<div>Side</div>
</div>4. Auto-Fit: Grids That Fill Any Container
Fixed column counts break when the container width is unknown (sidebars, modals). The auto-fit pattern creates as many columns as fit, each at least 240px wide:
<div className="grid gap-4 grid-cols-[repeat(auto-fit,minmax(240px,1fr))]">
{/* as many 240px+ columns as fit, no media queries needed */}
</div>This uses an arbitrary value (the square brackets). minmax(240px, 1fr) means each column is at least 240px and shares leftover space equally. It is the cleanest way to build card grids that "just work" at every width.
5. Real-World Patterns
Dashboard layout (sidebar + main)
<div className="grid grid-cols-12 gap-6">
<aside className="col-span-12 md:col-span-3">Sidebar</aside>
<main className="col-span-12 md:col-span-9">Content</main>
</div>Holy grail (header, 3 columns, footer)
<div className="grid grid-rows-[auto_1fr_auto] min-h-screen">
<header>Header</header>
<div className="grid md:grid-cols-[240px_1fr_240px]">
<aside>Left</aside>
<main>Content</main>
<aside>Right</aside>
</div>
<footer>Footer</footer>
</div>6. Grid Template Areas: Name Your Layout
For complex page layouts, named areas beat counting column lines. You draw the layout as a text map and assign items by name. Tailwind has no dedicated utility for this, so use arbitrary properties:
<div className="grid gap-4 grid-cols-3
[grid-template-areas:'header_header_header'_'nav_main_ads'_'footer_footer_footer']">
<header className="[grid-area:header]">Header</header>
<nav className="[grid-area:nav]">Nav</nav>
<main className="[grid-area:main]">Content</main>
<aside className="[grid-area:ads]">Ads</aside>
<footer className="[grid-area:footer]">Footer</footer>
</div>Rearranging the layout means editing the text map, not renumbering a dozen spans. For responsive versions, redefine the areas at each breakpoint with a prefixed arbitrary property.
7. Alignment: place-items and Friends
Grid alignment has two axes and two targets, which is why it confuses people. The mental model:
place-items-center: centers every item inside its own cell (both axes at once). The one you will use most.place-content-center: centers the whole grid tracks inside the container, when the grid is smaller than its parent.self-center/justify-self-end: override alignment for a single item without touching the rest.
If items look "stuck to the top" of tall cells, you are missing place-items-center (or items-center for the block axis only).
8. Three Gotchas That Bite Everyone
- Overflowing content. Grid items default to
min-width: auto, so long words or wide children can blow out the layout. Addmin-w-0to the item (oroverflow-hidden) to let it shrink. - Grid vs flex confusion. Use Grid when you align in two dimensions (rows AND columns). Use flexbox for a single row or column of items. A navbar is flex; a photo gallery is grid.
- Implicit rows. Extra items create implicit rows sized by content. Control them with
auto-rows-fr(equal heights) orauto-rows-[200px]for fixed-height rows.
# Expansion draft: tailwind-grid-guide
Subgrid: Finally, Nested Grids That Line Up
The existing guide covers spanning and template areas, but there is one layout problem neither solves cleanly: a card grid where each card is itself a grid, and you want the inner rows to align across cards. Before subgrid, the trick was fixed heights or JavaScript. Both are fragile.
Subgrid lets a nested grid inherit its parent's tracks. The card's inner grid uses the same row lines as the outer grid, so titles, images, and buttons line up across cards even when content lengths differ. Tailwind has utilities for it: grid-rows-subgrid and grid-cols-subgrid.
<div className="grid grid-cols-3 gap-6 grid-rows-[auto_auto_1fr_auto]">
{cards.map((card) => (
<article key={card.id} className="grid grid-rows-subgrid row-span-4 gap-0">
<img src={card.image} alt="" />
<h3>{card.title}</h3>
<p>{card.excerpt}</p>
<a href={card.url}>Read more</a>
</article>
))}
</div>Two details matter. First, the child must span the same tracks it wants to inherit, hence row-span-4 matching the four explicit rows. Second, subgrid only inherits in the axis you declare it on. I prefer reaching for subgrid whenever I catch myself adding min-h- classes just to force alignment. It removes a whole category of magic numbers.
Browser support is solid now. Subgrid shipped in Firefox years ago, then Chrome 117 and Safari 16 picked it up, so all modern browsers handle it. If your project still supports older Safari, test there first. Everywhere else, it just works.
grid-flow-dense: Packing the Holes (With a Catch)
When grid items span different numbers of tracks, you get holes: empty cells where a wide item could not fit. grid-flow-dense tells the auto-placement algorithm to backfill those holes with smaller items that come later in the DOM.
<div className="grid grid-cols-4 gap-4 grid-flow-dense">
<div className="col-span-2 row-span-2">Featured</div>
<div>Small</div>
<div>Small</div>
<div>Small</div>
{/* small items backfill the gaps beside Featured */}
</div>In practice I use this for dashboards and media galleries where packing efficiency matters more than strict order. But there is a real catch, and it is an accessibility one: dense flow changes visual order without changing DOM order. A keyboard user tabs through items in DOM order while seeing them in a different visual order. Screen readers announce them in DOM order too. For a photo gallery that is usually fine. For anything with a meaningful sequence, like steps in a process or a ranked list, dense flow is the wrong call. Keep the default sparse flow there and accept the holes.
Masonry Layout: Not Ready for Production
Every few months someone asks about Pinterest-style masonry with pure CSS Grid. The honest answer: the masonry spec work stalled, and the only implementation is Firefox's experimental grid-template-rows: masonry, which sits behind a flag and is off by default. There is no Tailwind utility for it because there is no stable CSS to wrap.
The workarounds people actually ship are CSS columns (columns-3 with break-inside-avoid on items) or a small JavaScript layout library. Columns are the pragmatic pick for image galleries: two utilities, no dependencies, and the column-fill order is top-to-bottom per column, which readers handle fine. What columns cannot do is keep items in strict left-to-right reading order across the row. If that order matters, you need JavaScript. Do not hold your breath for native masonry. It has been "coming" for years.
Debugging Grids in DevTools
Grid bugs are visual, so debug them visually. Chrome, Edge, and Firefox all ship a grid inspector: in the Elements panel, find the display: grid badge next to your container and click it. You get an overlay showing every track line, its number, and the gap gutters.
This overlay pays off in three specific situations. First, when a col-span-2 item lands somewhere unexpected, the numbered lines show you exactly which lines it spans, and you will usually spot that the item is starting one line later than you assumed. Second, when implicit rows appear out of nowhere, the overlay labels them differently from explicit tracks, which tells you the item count or spanning pushed content past your defined rows. Third, for the min-w-0 overflow gotcha from the main guide, the overlay shows the track sized wider than the container, which confirms the item is refusing to shrink before you touch any code.
One more habit: when a responsive grid misbehaves at one breakpoint, resize with the overlay on and watch which breakpoint's grid-cols-* is actually active. Half the time the "bug" is a breakpoint prefix typo, like md: where you meant lg:, and the overlay makes the active column count obvious at a glance.
FAQ
When should I use Grid instead of Flexbox?
Grid when you control two dimensions at once (rows and columns): card grids, dashboards, page layouts. Flexbox when items flow in one direction: navbars, button rows, centered content. A page can (and should) use both.
Why do my grid items overflow their columns?
Grid items default to min-width: auto, so wide content refuses to shrink. Add min-w-0 to the item and the overflow stops. This single class fixes the most reported grid bug in Tailwind projects.
How do I make all grid items the same height?
They already stretch by default (align-items: stretch). If rows look uneven, the content inside differs, not the cells. For explicit control, set auto-rows-fr so implicit rows share space equally.
Is auto-fit or auto-fill better for card grids?
auto-fit collapses empty tracks, so a row with two cards spreads them across the full width. auto-fill keeps empty tracks, leaving gaps. For card grids, auto-fit is almost always what you want.
Design grids visually, ship the classes
Drag columns, set gaps and spans on a live canvas, preview responsive breakpoints, then copy production-ready Tailwind classes.
Open the Grid Builder, it's freeTry it: related UI elements
Revenue
$48.2k
12.4%
Stat Card
Copy code →
Featured tile
Spans two columns for emphasis
Fast
Secure
Bento Grid Card
Copy code →
2024
Launched v1.0
First public release with core features.
2025
Reached 10k users
Community growth milestone.
2026
What's next
Roadmap in progress.
Vertical Timeline
Copy code →
Masonry Columns
Copy code →