Placing Grid Items: Line Numbers, Spans, Named Lines and grid-template-areas
Putting grid items where you want them: grid-column and grid-row with line numbers, negative numbers and span, named lines and the automatic -start and -end names, grid-template-areas for drawing layouts as text, grid-area, and responsive templates.
kvi5hnuCode Sprout team member7 min readOn this page
By default, grid items flow into the next free cell, one after another (article 69). Often you want more control: a header across the top, a sidebar in the first column, a featured card two columns wide. Grid lets you place each item by naming the lines it starts and ends at, or by drawing the whole layout as a template of named areas.
Line-based placement
Four properties set an item's edges, by line number (article 66):
.feature {
grid-column-start: 1;
grid-column-end: 3; /* from column line 1 to line 3: two columns */
grid-row-start: 2;
grid-row-end: 4; /* rows 2 and 3 */
}
The shorthands grid-column and grid-row take start / end:
.feature { grid-column: 1 / 3; grid-row: 2 / 4; }
Tested in Chrome, in a grid of four 100px columns:
| Placement | Result |
|---|---|
grid-column: 2 / 4 | starts at 100px, 200px wide: columns 2 and 3 |
grid-column: -3 / -1 | the last two columns: negative numbers count from the end of the explicit grid |
grid-column: 1 / -1 | the full width, whatever the number of columns |
grid-column: 3 / 1 | columns 1 and 2: a start after the end is swapped |
grid-column: 5 | a new implicit column after the four explicit ones |
With only a start line, the item spans one track: grid-column: 2 is 2 / auto, one column.

The second and fifth panels end up in the same place by different routes: two negative line numbers, or an end line plus a span.
span
span n sets a size instead of a line:
.wide { grid-column: span 2; } /* two columns, wherever auto-placement puts it */
.tall { grid-row: 2 / span 3; } /* from row line 2, three rows down */
.right { grid-column: span 2 / -1; } /* the last two columns: ends at -1, spans back 2 */
span without a start line leaves the position to auto-placement (article 69), which is how galleries mix wide and normal items without placing each one.
Placing outside the grid
If an item is placed at a line beyond the explicit grid, the grid grows implicit tracks to reach it. Tested in Chrome: in a four-column grid, an item with grid-column: 5 creates a fifth column, sized by grid-auto-columns. That's auto by default: in a 400px grid, exactly as wide as its four columns, the new column is 0px for an empty item, but in a wider grid an auto track stretches into the leftover space, so in a 720px grid it's 320px. Negative lines beyond the start create implicit tracks before the first column, which also shifts where auto-placed items go. It's usually a mistake: if items end up in thin, unexpected columns, look for a line number that's too large.
Named lines
Line numbers are fragile: adding a column renumbers everything. Lines can have names, written in square brackets in the track list:
.page {
display: grid;
grid-template-columns:
[full-start] minmax(1rem, 1fr)
[content-start] minmax(0, 60rem) [content-end]
minmax(1rem, 1fr) [full-end];
}
.page > * { grid-column: content; } /* between content-start and content-end */
.page > .hero { grid-column: full; } /* edge to edge */
- A line can have several names:
[sidebar-end main-start]. grid-column: contentuses a shortcut: for a namex, the linesx-startandx-endare used as start and end. Tested in Chrome: in a 400px grid with 50px margins,contentis 300px wide from 50px, andfullis 400px from 0.- Names can repeat, in
repeat(3, [col] 1fr)for example;grid-column: col 2means the second line namedcol, andspan col 2spans across twocollines.
grid-template-areas
For page layouts, the clearest tool is grid-template-areas: you draw the layout as strings, one per row, with a name for each cell.

.site {
display: grid;
grid-template-columns: 10rem 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"head head"
"nav main"
"nav foot";
}
.site-header { grid-area: head; }
.site-nav { grid-area: nav; }
.site-main { grid-area: main; }
.site-footer { grid-area: foot; }
The rules:
- Each string is a row; each name, separated by spaces, is a cell. All rows must have the same number of cells.
- A name repeated in neighbouring cells makes one area. Each area must be a rectangle; an L-shape or a name in two separate places makes the whole declaration invalid. Tested in Chrome:
"a b" "b a"computes tonone. - A dot (
., or several dots like...) is an empty cell. - Extra spaces are ignored, so the strings can be aligned to look like the layout.
- Items are put in areas with
grid-area: name. Items without agrid-areaare auto-placed into the remaining empty cells.

The dashed lines crossing the header and the nav are grid lines inside a spanning area: areas are built from cells, and the cells are still there.
Areas also create named lines: an area main defines main-start and main-end lines on both axes. So these mean the same thing (tested in Chrome):
.a { grid-area: main; }
.b { grid-column: main-start / main-end; grid-row: main-start / main-end; }
And the other way round: lines you name x-start and x-end create an implicit area x usable with grid-area: x.
grid-area with lines
grid-area also accepts up to four lines, in the order row-start / column-start / row-end / column-end, which is anticlockwise from the top, the opposite of margin:
.feature { grid-area: 2 / 1 / 4 / 3; } /* grid-row: 2 / 4; grid-column: 1 / 3 */
The line form is hard to read; grid-row and grid-column are clearer.
Rearranging at breakpoints
Because the template describes the layout in one place, a responsive layout is just a different template. The HTML stays the same:
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.frame { inline-size: var(--w, 20rem); container-type: inline-size; margin-top: 0.5rem; }
.site {
display: grid; gap: 0.4rem;
grid-template-columns: 1fr;
grid-template-areas: "head" "nav" "main" "aside" "foot";
}
@container (width > 18rem) {
.site {
grid-template-columns: 5rem 1fr 5rem;
grid-template-areas:
"head head head"
"nav main aside"
"foot foot foot";
}
}
header { grid-area: head; } nav { grid-area: nav; } main { grid-area: main; }
aside { grid-area: aside; } footer { grid-area: foot; }
.site > * { padding: 0.6rem; border-radius: 6px; background: #f4efe6; border: 1px solid #8a3b12; }
.site > main { min-block-size: 5rem; background: #dff0e5; border-color: #2f7d4f; }
Drag the slider below 18rem: the three-column template is replaced by a single column. This demo uses a container query (article 78) so it works inside the preview; on a real page, a media query works the same way.
Keep the HTML in a sensible reading order (article 64): placement only moves boxes, not the focus order or what screen readers read. reading-flow: grid-rows (Chrome 137+) makes the keyboard follow the grid's rows instead.
What's current
- Line placement,
span, named lines andgrid-template-areaswork in all browsers. reading-flowwithgrid-rows,grid-columnsorgrid-ordermakes focus follow a reordered grid, in Chrome 137+.- Subgrid (article 71) lets nested grids use the parent's line names.
Common questions
How do I make an item span the full width?
grid-column: 1 / -1. With named lines, grid-column: full if you've named full-start and full-end.
Why is my grid-template-areas ignored?
The value is invalid: an area isn't a rectangle, a name appears in two separate places, or the rows have different numbers of cells.
What order does grid-area: 1 / 2 / 3 / 4 use?
Row start, column start, row end, column end.
Why did an empty column appear in my grid? An item is placed at a line beyond the explicit grid, which creates implicit tracks.
Can two items be in the same area? Yes, they overlap (article 70).
Summary
grid-columnandgrid-rowtakestart / endlines; negative numbers count from the end, and1 / -1spans everything.span nsets a size; placing beyond the explicit grid creates implicit tracks.- Named lines in brackets make placement readable;
x-startandx-enddefine an areax. grid-template-areasdraws the layout as strings; areas must be rectangles;.is an empty cell.grid-areaplaces an item in a named area, or takes four lines: row-start, column-start, row-end, column-end.- Change the template at breakpoints to rearrange the layout without touching the HTML.
Practice questions
In a grid with five columns, which columns does each item cover?
.a { grid-column: 2 / -2; }
.b { grid-column: span 2 / -1; }
Answer
.a covers columns 2 to 4: line −2 is line 5 of 6. .b covers the last two columns, 4 and 5.
Write a grid-template-areas value for three columns: a header across the top, then a sidebar on the left with main spanning the other two columns, and a footer only under main.
Answer
grid-template-areas:
"head head head"
"side main main"
". foot foot";
Why is this value invalid?
grid-template-areas: "a a b" "a b b";
Answer
Neither a nor b is a rectangle: a is an L-shape covering two cells in the first row and one in the second, and so is b.
Write the grid-row and grid-column equivalent of this rule.
.x { grid-area: 1 / 3 / 3 / 5; }
Answer
.x { grid-row: 1 / 3; grid-column: 3 / 5; }
Previous: Grid Track Sizing: repeat(), minmax(), auto-fill, auto-fit and Intrinsic Sizes
Next: The Implicit Grid and Auto-Placement: grid-auto-rows, grid-auto-flow and dense

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.