CSS Grid Items & Placement
Chapter 30 covered the container properties that define the grid structure. This chapter covers the other half — properties applied to individual grid items. These let you place items precisely anywhere in the grid, span them across multiple rows or columns, align them within their cell, and even overlap them.
grid-column — place and span
across columnsgrid-row — place and span
across rowsspan keyword — span N
tracksgrid-area — four-value
shorthand or named areajustify-self & align-self — per-cell alignmentz-index
All Grid Item Properties — Quick Reference
These properties are applied to individual grid items (direct children of a grid container):
span N.span N.grid-column: start / end. Most common
way to place items.grid-row: start / end.grid-template-areas.
justify-items.align-items.align-self + justify-self in Grid. Both axes work here (unlike Flexbox).
grid-column — Column Placement
grid-column is shorthand for grid-column-start / grid-column-end. You specify which column lines the item
starts and ends at. All demos use a 4-column grid:
-1 is always the last line regardless of how many columns there are. grid-column: 1 / -1 always spans the full width — very useful for headers
and footers that must stretch across all columns.
/* grid-column: start / end */
.item { grid-column: 1 / 3; } /* lines 1→3, spans 2 cols */
.item { grid-column: 2 / 5; } /* lines 2→5, spans 3 cols */
.item { grid-column: 1 / -1; } /* full width (start to last line) */
.item { grid-column: 3; } /* col 3 only (start only → auto end) */
/* Longhand equivalents */
.item {
grid-column-start: 1;
grid-column-end: 3;
}
/* Named lines (from grid-template-columns: [col-start] 1fr [col-end]) */
.item { grid-column: col-start / col-end; }
/* Real-world: header spans all columns */
.header { grid-column: 1 / -1; }
.footer { grid-column: 1 / -1; }
grid-row — Row Placement
grid-row is the row equivalent of grid-column. It places the item by specifying start and end row lines. All
demos use a 3-row, 3-column grid:
1/3
all rows
/* grid-row: start / end */
.item { grid-row: 1 / 3; } /* lines 1→3, spans 2 rows */
.item { grid-row: 2 / 4; } /* lines 2→4, spans 2 rows */
.item { grid-row: 1 / -1; } /* all rows */
.item { grid-row: 2; } /* row 2 only */
/* Combined with grid-column */
.sidebar {
grid-column: 1 / 2;
grid-row: 2 / 4; /* rows 2–3 */
}
.hero {
grid-column: 1 / -1; /* full width */
grid-row: 1 / 2;
}
The span Keyword
Instead of specifying exact end line numbers, the span keyword lets you say "span N tracks from wherever this item
lands". It works with auto-placement so you don't need to know exact positions:
span 2
/* span N — span N tracks from current position */
.item { grid-column: span 2; } /* span 2 columns */
.item { grid-column: span 3; } /* span 3 columns */
.item { grid-row: span 2; } /* span 2 rows */
/* span from a fixed start position */
.item { grid-column: 2 / span 3; } /* start at col 2, span 3 */
.item { grid-row: 1 / span 2; } /* start at row 1, span 2 */
/* Compare: line numbers vs span */
.a { grid-column: 1 / 3; } /* absolute lines — same result as: */
.b { grid-column: 1 / span 2; } /* span from line 1 */
/* Real-world: featured card in a grid */
.card-featured {
grid-column: span 2;
grid-row: span 2;
}
grid-area — Shorthand and Named Areas
grid-area has two distinct uses. The first is as a
4-value line-number shorthand. The second is assigning an item to a named
area from grid-template-areas on the container:
(2 rows, 2 cols)
grid-area: 2/1/4/3
/* ── Form 1: 4-value line shorthand ──
grid-area: row-start / col-start / row-end / col-end */
.item { grid-area: 1 / 1 / 3 / 3; }
/* ↑row-s ↑col-s ↑row-e ↑col-e
= grid-row:1/3; grid-column:1/3; */
.item { grid-area: 2 / 1 / 4 / -1; } /* rows 2–3, full width */
/* ── Form 2: Named area from grid-template-areas ── */
.container {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
/* ⚠ Don't mix both forms for the same item */
justify-self & align-self — Per-Cell Alignment
In Grid, justify-self and align-self both work fully (unlike Flexbox where justify-self has no effect). They align an item within its grid cell along
the inline and block axes respectively:
justify-self — horizontal (inline axis)
align-self — vertical (block axis)
center ★
.container {
display: grid;
justify-items: stretch; /* default for all items */
align-items: stretch; /* default for all items */
}
/* justify-self: horizontal position within the cell */
.item { justify-self: stretch; } /* default — fills cell width */
.item { justify-self: start; } /* left edge of cell */
.item { justify-self: end; } /* right edge of cell */
.item { justify-self: center; } /* centred horizontally */
/* align-self: vertical position within the cell */
.item { align-self: stretch; } /* default — fills cell height */
.item { align-self: start; } /* top of cell */
.item { align-self: end; } /* bottom of cell */
.item { align-self: center; } /* vertically centred */
/* place-self: shorthand for align-self + justify-self */
.item { place-self: center; } /* centred in cell both ways */
.item { place-self: start end; } /* top-right of cell */
/* ✓ In Grid: justify-self works (unlike Flexbox!) */
Overlapping Items & z-index
CSS Grid items can occupy the same cells. This is intentional — you
explicitly assign two items to overlapping positions. Control which one appears on top with z-index:
Purple item assigned to grid-column:1/3 + grid-row:1/3. z-index:1 puts it on top.
.grid {
display: grid;
grid-template-columns:repeat(3, 1fr);
grid-template-rows: repeat(2, 100px);
}
/* Two items placed in the same area */
.background-image {
grid-column: 1 / 3;
grid-row: 1 / 3;
z-index: 0; /* behind */
}
.overlay-text {
grid-column: 1 / 3;
grid-row: 1 / 3; /* same cells! */
z-index: 1; /* on top */
place-self: center;
}
/* Real use: photo card with text overlay */
.photo { grid-area: 1 / 1 / 3 / 4; z-index: 0; }
.caption { grid-area: 2 / 1 / 3 / 4; z-index: 1; align-self: end; }
Real-World Placement Patterns
Putting it all together — the most common page and component layout patterns using grid placement:
col:1
col:2
col:1/3, row:1/3
/* ── Pattern 1: Classic page layout ── */
.page {
display: grid;
grid-template-columns:260px 1fr;
grid-template-rows: 64px 1fr 48px;
min-height: 100vh;
}
.header { grid-column: 1 / -1; } /* full width */
.sidebar { grid-row: 2; } /* auto-placed in col 1 */
.main { grid-row: 2; } /* auto-placed in col 2 */
.footer { grid-column: 1 / -1; } /* full width */
/* ── Pattern 2: Featured article ── */
.magazine { grid-template-columns: repeat(3, 1fr); }
.featured {
grid-column: 1 / 3; /* spans 2 cols */
grid-row: 1 / 3; /* spans 2 rows */
}
/* ── Pattern 3: Dashboard ── */
.dashboard { grid-template-columns: repeat(4, 1fr); }
.full-chart { grid-column: 1 / -1; } /* spans all 4 cols */
All Item Properties — Complete Reference
| Property | Default | Values | Controls |
|---|---|---|---|
| grid-column-start | auto | integer, named line, span N | Start column line |
| grid-column-end | auto | integer, named line, span N | End column line |
| grid-column | auto / auto | start / end | Shorthand: column placement |
| grid-row-start | auto | integer, named line, span N | Start row line |
| grid-row-end | auto | integer, named line, span N | End row line |
| grid-row | auto / auto | start / end | Shorthand: row placement |
| grid-area | auto/auto/auto/auto | row-s/col-s/row-e/col-e or area-name | Shorthand: all placement or named area |
| justify-self | stretch | stretch, start, end, center | Inline axis within cell |
| align-self | stretch | stretch, start, end, center | Block axis within cell |
| place-self | stretch stretch | align-self + justify-self | Both axes within cell |
Try It Yourself
All placement properties in one editor. Try changing line numbers, adding span, and experimenting with justify-self and align-self:
Quick Check — Chapter 31
grid-column: 1 / 3 — uses absolute line numbers.
The item starts at column line 1 and ends at column line 3, spanning 2 columns. This is explicit about
both start and end position.grid-column: span 2 — says "span 2 columns from
wherever auto-placement puts me." The start position is determined by the auto-placement algorithm. This
is relative — the item will span 2 columns from its natural position.When to use each:
— Use line numbers (
1 / 3) when the exact position matters (e.g.,
header must always start at column 1)— Use
span when only the size matters and position can be auto
(e.g., featured cards in a flowing grid)They can also be combined:
grid-column: 2 / span 3 means "start at
line 2 and span 3 columns" = lines 2 to 5.
grid-column: 1 / -1 makes an item span from the first column line to
the last column line — effectively making it full width across all columns.The
-1 is a negative line reference. In CSS Grid, lines can be
counted from the end: -1 is always the last line, -2 is second from last, and so on.This is especially useful for header and footer elements in a multi-column layout. Instead of knowing the exact number of columns and writing
1 / 5 for
a 4-column grid, you write 1 / -1 and it works for any number of
columns. If you later change from 3 to 4 columns, the header/footer still spans the full width without
changing the item CSS.
grid-area has two completely different but valid syntaxes:Form 1 — 4-value line shorthand:
grid-area: row-start / col-start / row-end / col-endFor example:
grid-area: 1 / 1 / 3 / 3 is exactly equivalent to
writing both grid-row: 1/3 and grid-column: 1/3. Note the order: row-start first, then
column-start.Form 2 — Named area reference:
grid-area: header — assigns the item to a named area defined by
grid-template-areas on the container. This is the most readable form
for page layouts.The two forms are mutually exclusive for a single item. Use form 1 for precise numeric placement; use form 2 when working with
grid-template-areas for named, semantic
layouts. Don't mix them on the same item.
justify-self works in Grid but
has no effect in Flexbox:In CSS Grid: Each item has its own cell (or area).
justify-self aligns the item within that cell along the inline
(horizontal) axis. Values: stretch (default), start, end, center. This works because each grid item has a defined cell boundary to
align within.In Flexbox:
justify-self is defined but has no
effect. Flexbox distributes items along the main axis collectively via justify-content — there is no per-item main-axis positioning. The
workaround in Flexbox is margin: auto.This is one reason Grid is more powerful for precise layouts — both axes have per-item control via
justify-self and align-self, while
Flexbox only provides per-item cross-axis control (align-self).
grid-column / grid-row) into the
same cells or overlapping cell ranges. This is intentional and powerful.How to make items overlap:
Assign two items to the same or overlapping cell ranges:
.background { grid-column: 1/4; grid-row: 1/3; }.overlay { grid-column: 1/4; grid-row: 1/3; }Controlling stacking order: Use
z-index. Higher
values appear on top. Items without explicit z-index stack in DOM order (later items on top).Common use cases:
— Full-bleed background image with text overlay
— Photo caption at the bottom of an image cell
— Decorative accent element behind content
— Badge or label overlaid on a card
Unlike absolute positioning, overlapping grid items still participate in the grid layout — they don't affect the placement of other items.
grid-column: 1 / -1 do?grid-area?grid-column: 2 / span 3. Which
column lines does it occupy?grid-column: start / end— places item between column lines.1/-1= full width. Negative numbers count from the end.grid-row: start / end— places item between row lines. Same syntax and negative-number support as grid-column.span N— span N tracks from current position. Can be combined with a start:2 / span 3= start at line 2, span 3 columns.grid-area— two forms: (1) 4-value:row-start / col-start / row-end / col-end. (2) Named:grid-area: header— must match a name ingrid-template-areas.justify-self— horizontal alignment within the cell (stretch/start/end/center). Works in Grid (unlike Flexbox).align-self— vertical alignment within the cell. Same values.place-self— shorthand for align-self + justify-self.place-self: center= centred in cell on both axes.- Overlapping — assign two items to the same cell ranges. Use
z-indexto control stacking order. - Key patterns:
header { grid-column: 1/-1 }for full-width header/footer.featured { grid-column: span 2; grid-row: span 2; }for featured cards.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.