Grid Placement in Tailwind CSS
Chapter 13 gave you the grid container. Now take precise control
of where items land. CSS Grid numbers every column and
row boundary — these are called grid lines.
col-start-* /
col-end-* and
row-start-* /
row-end-* pin any item to any
intersection. Add
grid-flow-* to direct
auto-placement and
auto-cols-* /
auto-rows-* to size the tracks
the browser creates automatically.
col-start-* and
col-end-*
row-start-* and
row-end-*
grid-flow-row,
grid-flow-col, and grid-flow-dense
auto-cols-* and
auto-rows-*
Grid Lines — The Invisible Coordinate System
Every CSS Grid has an invisible coordinate system. For a 4-column
grid, CSS creates
5 vertical lines numbered 1 to 5 (left to right).
It also numbers them from the right as -1 to -5. Row lines work
the same way vertically.
col-start-* and
col-end-*
use these line numbers to pin items to exact positions — like
giving GPS coordinates to each grid child.
col-end-[-1] always means
the last line regardless of column count.
col-start-2 col-end-4
pins an item from line 2 to line 4 — spanning exactly 2
columns regardless of what other items do.
col-start-3 col-span-2
means "start at line 3, be 2 columns wide" — cleaner than
specifying an end line.
col-start-* & col-end-* — Column Placement
col-start-N sets the column
line where an item begins.
col-end-N sets the line where
it ends (exclusive — the item stops at that line, not
inside it). Together they give precise control over horizontal
position — replacing
col-span-*
when you need exact pinning, not just a width.
col-start-2 starts at line 2, leaving the first
column empty.
col-start-2 col-end-4 spans lines 2–4, covering
exactly 2 columns.
col-start-3 col-span-2 is often cleaner than
col-start-3 col-end-5: state where to start and
how wide, not where to end.
<!-- 4-col grid: sidebar + main explicit placement -->
<div class="grid grid-cols-4 gap-4 min-h-screen">
<!-- Sidebar: col 1 only (line 1 to line 2) -->
<aside class="col-start-1 col-end-2 bg-gray-900 p-4 rounded-xl">
Sidebar
</aside>
<!-- Main: cols 2–4 (line 2 to line 5) -->
<main class="col-start-2 col-end-5 bg-gray-800 p-6 rounded-xl">
Main content (3 cols wide)
</main>
<!-- Footer: always full width using negative line -->
<footer class="col-start-1 col-end-[-1] bg-gray-950 p-4 rounded-xl">
Full-width footer (works for any column count)
</footer>
</div>
<!-- Cleaner: combine start + span -->
<div class="grid grid-cols-12 gap-4">
<div class="col-start-2 col-span-10 bg-blue-900 p-4 rounded-xl">
Centred content (skips 1 col each side)
</div>
</div>
row-start-* & row-end-* — Row Placement
Row placement mirrors column placement — just on the vertical
axis.
row-start-N sets the top line
and row-end-N sets the bottom
line (exclusive). Combine row and column placement to position any
item at any cell intersection — the foundation of full editorial
grid layouts.
row-start-2 starts below the first row track.
row-start-2 row-end-4 spans rows 2–3, two row
tracks tall.
row-span-* is also set.
row-start-2 row-span-2 is often clearer than
row-start-2 row-end-4. State start position and
height in tracks.
<!-- App shell: header / sidebar+main / footer -->
<div class="grid grid-cols-[240px_1fr] grid-rows-[64px_1fr_56px] min-h-screen gap-0">
<!-- Header: spans all columns, occupies row track 1 -->
<header class="col-start-1 col-end-[-1] row-start-1 row-end-2
bg-gray-900 px-6 flex items-center">
Navbar
</header>
<!-- Sidebar: column 1, row track 2 -->
<aside class="col-start-1 col-end-2 row-start-2 row-end-3
bg-gray-800 p-4 overflow-y-auto">
Side Navigation
</aside>
<!-- Main: column 2, row track 2 -->
<main class="col-start-2 col-end-3 row-start-2 row-end-3
bg-white p-8 overflow-auto">
Page content
</main>
<!-- Footer: spans all columns, row track 3 -->
<footer class="col-start-1 col-end-[-1] row-start-3 row-end-4
bg-gray-950 px-6 flex items-center">
Footer
</footer>
</div>
grid-flow-* — Auto-Placement Direction
When grid items don't have explicit placement, the browser
auto-places them using the
grid auto-placement algorithm.
grid-flow-* controls which
direction the algorithm walks: row by row (default), column by
column, or with dense packing
to backfill gaps left by larger items.
auto-cols-* and overflow-x-auto it
creates a horizontal scroll strip.
grid-flow-col would
leave column gaps that smaller items can fill.
<!-- grid-flow-row-dense: fills gaps in bento grid -->
<div class="grid grid-cols-3 grid-flow-row-dense gap-4">
<div class="col-span-2 bg-cyan-900 p-4 rounded-xl">Wide card (leaves 1 col gap)</div>
<div class="col-span-2 bg-cyan-900 p-4 rounded-xl">Wide card</div>
<div class="bg-cyan-700 p-4 rounded-xl">Small — fills first gap</div>
<div class="bg-cyan-700 p-4 rounded-xl">Small — fills next gap</div>
</div>
<!-- grid-flow-col: horizontal strip (top-to-bottom per column) -->
<div class="grid grid-rows-1 grid-flow-col auto-cols-[280px] gap-4 overflow-x-auto">
<div class="bg-purple-900 p-6 rounded-xl h-44">Card A</div>
<div class="bg-purple-900 p-6 rounded-xl h-44">Card B</div>
<div class="bg-purple-900 p-6 rounded-xl h-44">Card C</div>
</div>
auto-cols-* & auto-rows-* — Implicit Track Sizing
When the grid auto-placement algorithm creates new tracks beyond
your defined
grid-cols-* or
grid-rows-*, those are called
implicit tracks. By default they size to fit
their content. auto-rows-* and
auto-cols-*
give you control — ensuring consistent card heights or a
precise-width horizontal scroll strip.
grid-flow-col creates new columns beyond the
defined grid.
grid-flow-col gets an equal share of the row
width.
auto-rows-[120px] makes every implicit row
exactly 120px. Most practical use: consistent card-grid row
heights without hardcoding each row in
grid-rows-*.
<!-- 1. Uniform card heights with auto-rows -->
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 auto-rows-[240px] gap-6">
<div class="bg-gray-800 rounded-2xl overflow-hidden">Card A</div>
<div class="bg-gray-800 rounded-2xl overflow-hidden col-span-2">Wide card</div>
<div class="bg-gray-800 rounded-2xl overflow-hidden">Card C</div>
</div>
<!-- Every implicit row is exactly 240px regardless of content -->
<!-- 2. Horizontal scroll strip with grid-flow-col + auto-cols -->
<div class="grid grid-rows-1 grid-flow-col auto-cols-[280px] gap-4 overflow-x-auto pb-2">
<div class="bg-cyan-900 rounded-xl p-6 h-44">Card 1</div>
<div class="bg-cyan-900 rounded-xl p-6 h-44">Card 2</div>
<div class="bg-cyan-900 rounded-xl p-6 h-44">Card 3</div>
<div class="bg-cyan-900 rounded-xl p-6 h-44">Card 4</div>
<div class="bg-cyan-900 rounded-xl p-6 h-44">Card 5</div>
</div>
grid grid-rows-1 grid-flow-col auto-cols-[280px]
overflow-x-auto) is more predictable than Flexbox for this use case — each card
is exactly 280px regardless of content. Add
snap-x snap-mandatory to the container and
snap-start to each card for native CSS scroll
snapping with no JavaScript.
Real-World: Magazine Layout
Combining col-start-*,
col-end-*,
row-start-*,
row-end-*, and
auto-rows-[...] gives you full
editorial control — a magazine layout with a large hero, a sidebar
stack, a breaking news band, and a horizontal teaser strip, all
from Tailwind utilities without custom CSS.
<!-- 12-col grid, 3 row heights: hero / band / teaser strip -->
<div class="grid grid-cols-12 grid-rows-[340px_auto_200px]
gap-4 p-4 bg-gray-950 min-h-screen">
<!-- Hero story: 8 cols wide, row 1 -->
<article class="col-start-1 col-span-8 row-start-1 row-end-2
relative rounded-2xl overflow-hidden bg-gray-800">
<img src="hero.jpg" alt="Hero" class="w-full h-full object-cover">
<div class="absolute bottom-0 left-0 right-0 p-6
bg-gradient-to-t from-black/80 to-transparent">
<span class="text-xs text-cyan-400 font-semibold uppercase tracking-wider">Tech</span>
<h2 class="text-3xl font-bold text-white mt-1">Tailwind CSS v4 is Here</h2>
</div>
</article>
<!-- Sidebar stack: last 4 cols, row 1 -->
<div class="col-start-9 col-end-[-1] row-start-1 row-end-2 flex flex-col gap-4">
<article class="flex-1 bg-gray-800 rounded-2xl p-4">Side Story 1</article>
<article class="flex-1 bg-gray-800 rounded-2xl p-4">Side Story 2</article>
</div>
<!-- Breaking news band: full width, row 2 -->
<div class="col-start-1 col-end-[-1] row-start-2 row-end-3
bg-cyan-600 text-white px-6 py-3 rounded-xl flex items-center gap-4">
<span class="font-bold text-sm uppercase tracking-widest shrink-0">Breaking</span>
<p class="text-sm">CSS Grid Placement supported in all major browsers</p>
</div>
<!-- Teaser strip: horizontal scroll, row 3 -->
<div class="col-start-1 col-end-[-1] row-start-3 row-end-4
grid grid-rows-1 grid-flow-col auto-cols-[240px] gap-4 overflow-x-auto pb-2">
<article class="bg-gray-800 rounded-xl p-4">Teaser 1</article>
<article class="bg-gray-800 rounded-xl p-4">Teaser 2</article>
<article class="bg-gray-800 rounded-xl p-4">Teaser 3</article>
<article class="bg-gray-800 rounded-xl p-4">Teaser 4</article>
<article class="bg-gray-800 rounded-xl p-4">Teaser 5</article>
</div>
</div>
Quick Reference — All Grid Placement Utilities
| Class | CSS Property | Notes |
|---|---|---|
col-start-1…13 |
grid-column-start: N |
Pin item left edge to line N |
col-start-auto |
grid-column-start: auto |
Browser auto-places item ★ |
col-end-1…13 |
grid-column-end: N |
Pin item right edge (exclusive) |
col-end-auto |
grid-column-end: auto |
Browser calculates end automatically |
col-start-1 col-end-[-1] |
grid-column: 1 / -1 |
Full-width row — any col count ★ |
col-start-N col-span-M |
grid-column: N / span M |
Start at line N, M cols wide ★ |
row-start-1…7 |
grid-row-start: N |
Pin item top edge to row line N |
row-start-auto |
grid-row-start: auto |
Browser auto-places in next row |
row-end-1…7 |
grid-row-end: N |
Pin item bottom edge (exclusive) |
row-end-auto |
grid-row-end: auto |
Browser calculates end automatically |
row-start-N row-span-M |
grid-row: N / span M |
Start at row N, M rows tall ★ |
grid-flow-row |
grid-auto-flow: row |
Default — L→R, new rows ★ |
grid-flow-col |
grid-auto-flow: column |
T→B, new columns |
grid-flow-dense |
grid-auto-flow: dense |
Fill gaps (changes DOM order) |
grid-flow-row-dense |
grid-auto-flow: row dense |
Row + dense packing ★ |
grid-flow-col-dense |
grid-auto-flow: column dense |
Column + dense packing |
auto-cols-auto |
grid-auto-columns: auto |
Implicit cols fit content |
auto-cols-min |
grid-auto-columns: min-content |
Narrowest content width |
auto-cols-max |
grid-auto-columns: max-content |
Widest content width |
auto-cols-fr |
grid-auto-columns: minmax(0,1fr) |
Share available space equally |
auto-rows-[120px] |
grid-auto-rows: 120px |
Fixed implicit row height ★ |
auto-cols-[280px] |
grid-auto-columns: 280px |
Fixed col width — scroll strip ★ |
★ = most commonly used in real projects
-
Grid lines — A 4-column grid has 5 vertical
lines numbered 1–5 (L→R) and also -1 to -5
(R→L).
col-end-[-1]always means the last line regardless of how many columns the grid has. -
col-start / col-end — Pin any item to any
column line.
col-start-2 col-end-4spans lines 2–4, covering exactly 2 columns. End is exclusive. -
col-start + col-span — Combine for clarity:
col-start-3 col-span-2reads "start at line 3, span 2 columns wide" — often cleaner than specifying an end line. -
row-start / row-end — Vertical counterpart to
column placement. Use both together for full 2D control:
col-start-1 col-end-2 row-start-2 row-end-4= exact cell intersection. - grid-flow-row-dense — After placing all items normally, backfills gaps with smaller items. Essential for bento grids where wide cards leave empty cells.
-
grid-flow-col — Changes auto-placement to
top-to-bottom. Pair with
auto-cols-[280px]andoverflow-x-autofor a horizontal scroll strip. -
auto-rows-[N] — Gives all implicit rows a fixed
height. Most practical:
auto-rows-[240px]makes every card-grid row exactly 240px without hardcoding each row ingrid-rows-*. -
Next chapter covers Padding — the
p-*,px-*,py-*,pt-*utilities and the 4px spacing scale used throughout every Tailwind layout.
Quick Check — Questions & Answers
Test your understanding of this chapter. Click a question to reveal the answer.
-1 always refers to the
last vertical line (the right edge of the
grid).
This is why col-start-1 col-end-[-1] creates
a full-width item regardless of how many columns the grid
has — it always spans from the first to the very last
line.
col-end-3 says "stop at line 3" — an absolute
position. If the item starts at line 1 it spans 2 columns.
If it starts at line 2, it spans only 1 column.
col-span-3 says "be 3 columns wide" — a
relative width.
col-start-2 col-span-3 occupies lines
2–5 (columns 2, 3, 4) regardless of context.
Use col-end-* when the end position matters
absolutely. Use col-span-* when the width
matters. Combining start + span is usually the clearest
pattern.
Use grid-flow-dense (or
grid-flow-row-dense) when your grid has items
of different sizes — like a bento layout where some cards
span 2 columns — and you don't want the grid to leave gaps
after wider items.
Accessibility trade-off: dense packing can move items out of DOM order. A smaller item from position 5 in the HTML might visually appear before item 3 to fill a gap. This breaks keyboard navigation and screen reader order since tab order follows DOM order, not visual order.
Only use dense packing for purely decorative grids where order doesn't matter. Never use it for navigation links or interactive form elements.
An implicit track is a row or column the browser creates automatically when grid items overflow the explicitly defined tracks.
Example: you define grid-cols-3 and place 9
items. The browser creates 3 rows automatically — those
are implicit. By default they size to fit content, causing
uneven heights in a card grid.
Control implicit row size with auto-rows-*:
auto-rows-[240px] makes every auto-created
row exactly 240px tall. Control implicit column size
(created by grid-flow-col) with
auto-cols-*:
auto-cols-[280px] makes every auto-column
exactly 280px wide.
Combine grid-rows-1 (one row),
grid-flow-col (items flow left-to-right as
new columns), auto-cols-[280px] (each
implicit column is exactly 280px wide), and
overflow-x-auto (horizontal scroll when
content exceeds container):
<div class="grid grid-rows-1 grid-flow-col
auto-cols-[280px] gap-4 overflow-x-auto">
Each child becomes a 280px-wide card in a single row. The
grid grows rightward automatically. This is more
predictable than Flexbox because each card has an exact
width. Add snap-x snap-mandatory to the
container and snap-start to each card for
native CSS scroll snapping.
MCQ Quiz — Test Yourself
Select the best answer for each question. Correct answers are revealed after you click.
col-start-2 col-end-4
do?
grid-flow-*
value places items top-to-bottom, creating new columns as
needed?
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.