Mastering CSS Grid Layouts (Part 2): Placement, Named Lines and Grid Areas
Learn deliberate CSS Grid placement with line numbers, spans, named lines, grid-template-areas, overlapping items, responsive rearrangement and maintainable page-layout patterns.

Once you understand how Grid sizes tracks, placement becomes much less mysterious.
Every item can be positioned by the grid lines around it. You can use numbers, names, spans or named areas. The syntax is flexible enough to build everything from a simple article shell to a dense dashboard, but that flexibility creates a maintenance trap: it is easy to produce a layout full of unexplained numbers that only its original author understands.
The aim of this part is not to teach every placement property in isolation. It is to show which placement model fits which kind of layout and how to keep the CSS readable when the page changes six months later.
Line-based placement is the underlying model
Suppose a container has four columns:
.grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1rem;
}
Four tracks create five vertical grid lines:
1 2 3 4 5
| col 1 | col 2 | col 3 | col 4 |
You can place an item from line 2 to line 4:
.item {
grid-column-start: 2;
grid-column-end: 4;
}
or use the shorthand:
.item {
grid-column: 2 / 4;
}
Rows work the same way:
.item {
grid-row: 1 / 3;
}
And both axes can be expressed together with grid-area, although the shorthand order is easy to forget:
.item {
grid-area: 1 / 2 / 3 / 4;
}
which means:
row-start / column-start / row-end / column-end
For day-to-day code, separate grid-column and grid-row declarations are often clearer unless you genuinely benefit from the four-value shorthand.
1 / -1 is the clean way to span the explicit grid
One of the most useful Grid patterns is:
.header {
grid-column: 1 / -1;
}
Negative line numbers count backwards from the end of the explicit grid.
So 1 / -1 means:
Start at the first explicit line and end at the final explicit line.
This is ideal for headers, footers, full-width alerts and section dividers.
.page {
display: grid;
grid-template-columns: 16rem minmax(0, 1fr) 18rem;
}
.page-header,
.page-footer {
grid-column: 1 / -1;
}
Remember the caveat from Part 1: negative line numbers refer to the explicit grid, not an indefinitely growing implicit grid.
span expresses size without hard-coding the destination
If an item simply needs to occupy two tracks, you often do not care exactly where its final line is.
.feature-card {
grid-column: span 2;
}
Grid can auto-place the item while respecting its two-track width.
This is excellent for mixed card collections:
.cards {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1rem;
}
.card--wide {
grid-column: span 2;
}
.card--hero {
grid-column: span 2;
grid-row: span 2;
}
The ordinary cards require no coordinates at all.
That is usually more robust than assigning every card a fixed row and column.
When line numbers become unreadable
This is technically valid:
.sidebar {
grid-column: 1 / 2;
grid-row: 2 / 5;
}
.main {
grid-column: 2 / 8;
grid-row: 2 / 4;
}
.related {
grid-column: 8 / 11;
grid-row: 2 / 4;
}
But you have to reconstruct the grid in your head to understand what any declaration means.
If the layout has semantic regions, named lines or named areas can be much easier to maintain.
Named grid lines make line-based placement self-documenting
You can name lines inside the track definition:
.page {
display: grid;
grid-template-columns:
[page-start] 1rem
[content-start] minmax(0, 1fr)
[content-end] 1rem
[page-end];
}
Then place content by name:
.article {
grid-column: content-start / content-end;
}
.full-bleed {
grid-column: page-start / page-end;
}
This pattern is particularly powerful in editorial layouts where most content sits in a readable central column but selected images or callouts extend beyond it.
For example:
.article-layout {
display: grid;
grid-template-columns:
[full-start] minmax(1rem, 1fr)
[wide-start] minmax(0, 8rem)
[content-start] minmax(0, 42rem)
[content-end] minmax(0, 8rem)
[wide-end] minmax(1rem, 1fr)
[full-end];
}
.article-layout > * {
grid-column: content-start / content-end;
}
.article-layout .wide {
grid-column: wide-start / wide-end;
}
.article-layout .full {
grid-column: full-start / full-end;
}
Now your HTML can simply apply wide or full where appropriate.
The CSS communicates intent far better than grid-column: 2 / 6.
A single line can have multiple names
Grid lines are not limited to one identifier.
grid-template-columns:
[sidebar-start page-start] 16rem
[sidebar-end content-start] minmax(0, 1fr)
[content-end page-end];
The middle line is both sidebar-end and content-start.
That makes semantic placement expressive:
.sidebar {
grid-column: sidebar-start / sidebar-end;
}
.content {
grid-column: content-start / content-end;
}
The geometry and semantics can coexist without duplicating tracks.
Named areas are excellent for page regions
For layouts with clear semantic regions, grid-template-areas can be the most readable approach.
.page {
display: grid;
grid-template-columns: 16rem minmax(0, 1fr) 18rem;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}
Then assign items:
.header { grid-area: header; }
.nav { grid-area: nav; }
.main { grid-area: main; }
.aside { grid-area: aside; }
.footer { grid-area: footer; }
This is one of those rare CSS declarations that looks almost like a diagram of the page.
A developer can understand the structure without mentally converting line numbers.
Area names create lines too
Named areas have another useful property: the browser creates implicit line names based on each area.
Given:
grid-template-areas:
"nav main";
the grid exposes names corresponding to boundaries such as nav-start, nav-end, main-start and main-end in the relevant axes.
You do not need to use them for ordinary area placement, but it demonstrates how areas and line placement are two views of the same underlying grid.
Rules for valid grid-template-areas
An area must form a rectangle.
This is valid:
grid-template-areas:
"hero hero"
"nav main";
This is not a valid single hero area:
grid-template-areas:
"hero hero"
"hero main";
because the named region would form an L shape rather than a rectangle.
Use a different area name or structure the layout another way.
You can represent empty cells with a dot:
grid-template-areas:
"nav main .";
Multiple dots are commonly used for visual readability:
grid-template-areas:
"nav main ....";
Responsive rearrangement with named areas
Named areas shine when a page needs to change composition at a breakpoint.
Desktop:
.page {
display: grid;
grid-template-columns: 16rem minmax(0, 1fr) 18rem;
grid-template-areas:
"header header header"
"nav main aside"
"footer footer footer";
}
Narrow layout:
@media (max-width: 52rem) {
.page {
grid-template-columns: minmax(0, 1fr);
grid-template-areas:
"header"
"nav"
"main"
"aside"
"footer";
}
}
The individual child rules do not change:
.main { grid-area: main; }
Only the page map changes.
That is much cleaner than rewriting grid-row and grid-column values for every item at each breakpoint.
But visual rearrangement can create accessibility problems
Grid gives you enormous visual freedom.
That does not mean you should make DOM order meaningless.
Imagine the source order is:
<header>...</header>
<main>...</main>
<nav>...</nav>
<footer>...</footer>
and CSS visually places nav before main.
A sighted mouse user sees navigation first. A keyboard or assistive-technology user may encounter focus/reading order based largely on the document source rather than the visual arrangement.
The safest rule is:
Keep source order logical without CSS. Use Grid for layout, not for repairing semantically poor markup.
Visual reordering should be a deliberate enhancement, not the foundation of the reading sequence.
Overlap is a first-class Grid feature
Grid items may occupy the same cells.
That makes overlays and layered hero layouts straightforward.
.hero {
display: grid;
}
.hero > * {
grid-area: 1 / 1;
}
Now the image and text share the same grid area.
<section class="hero">
<img src="hero.jpg" alt="">
<div class="hero-content">
<h1>Build something better</h1>
</div>
</section>
Then control stacking and alignment:
.hero img {
width: 100%;
height: 100%;
object-fit: cover;
}
.hero-content {
z-index: 1;
align-self: end;
padding: 2rem;
}
No absolute positioning is required merely to make the layers overlap.
That can keep the container’s intrinsic height and layout behaviour easier to reason about.
Use z-index deliberately when grid items overlap
Grid items can participate in stacking with z-index even without position: relative in the ordinary Grid overlap case.
.background {
grid-area: 1 / 1;
z-index: 0;
}
.content {
grid-area: 1 / 1;
z-index: 1;
}
As with any stacking logic, keep the layering simple.
If your component requires z-index: 999999 because several ancestors have created unexpected stacking contexts, the problem is probably larger than Grid.
Placement can create implicit tracks unexpectedly
Suppose the explicit grid has three columns:
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
Then an item says:
.item {
grid-column: 5;
}
Grid does not simply ignore the request. It may create implicit tracks to make the placement possible.
This can result in mysterious extra columns.
When a layout suddenly becomes wider than expected, inspect whether a child has been placed outside the explicit lines.
DevTools Grid overlays make this obvious.
grid-auto-flow: dense fills holes, but it can change visual order
When items have different spans, auto-placement can leave holes.
.grid {
grid-auto-flow: dense;
}
tells Grid to backfill suitable later items into earlier gaps.
Visually, this can create a compact masonry-like arrangement.
But there is an important trade-off: a later DOM item may appear visually before an earlier one.
That can make keyboard and reading order confusing.
Use dense for collections where visual ordering is not semantically important — for example some decorative image galleries — and avoid it when chronology or focus sequence matters.
Place by intent, not because every item needs coordinates
A maintainable Grid layout usually combines several strategies:
ordinary repeated content -> auto-placement
special card sizing -> span
semantic page regions -> named areas
editorial alignment -> named lines
one-off exact placement -> line numbers
Trying to solve every layout with the same placement method makes CSS harder than it needs to be.
A dashboard example with mixed strategies
Markup:
<div class="dashboard">
<header class="dashboard__header">...</header>
<nav class="dashboard__nav">...</nav>
<main class="dashboard__main">
<section class="stats">...</section>
</main>
</div>
Page regions:
.dashboard {
min-height: 100dvh;
display: grid;
grid-template-columns: 15rem minmax(0, 1fr);
grid-template-rows: auto minmax(0, 1fr);
grid-template-areas:
"header header"
"nav main";
}
.dashboard__header { grid-area: header; }
.dashboard__nav { grid-area: nav; }
.dashboard__main { grid-area: main; min-width: 0; }
Repeated cards inside the main region:
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
gap: 1rem;
}
One important card can be larger:
.stat--primary {
grid-column: span 2;
}
The outer grid uses named areas because the regions are semantic. The inner grid uses auto-placement because the cards are repetitive. The exceptional card uses span.
That is a good example of Grid features cooperating rather than competing.
Ship the layout, then inspect the whole page
SiteTidy can audit the deployed page for technical, metadata, performance and security issues once your Grid work reaches production.
Named lines are often better for design systems
If you are creating a reusable page shell, named lines can become layout API primitives.
.layout {
display: grid;
grid-template-columns:
[full-start] minmax(1rem, 1fr)
[content-start] minmax(0, 70rem)
[content-end] minmax(1rem, 1fr)
[full-end];
}
Then child components can opt into the width they need:
.layout > * {
grid-column: content-start / content-end;
}
.layout > .full-width {
grid-column: full-start / full-end;
}
This is more stable than coupling components to column numbers such as 2 / 3, because the internal track count can evolve while the semantic line names remain meaningful.
Use named areas when the map is the documentation
A good test is this:
Would another developer understand the page faster by seeing this?
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
If yes, use named areas.
Would the layout require dozens of tiny area names such as title, icon, label, separator, button1, button2 just to position a small reusable component?
Then line placement, Flexbox or a simpler nested grid may be clearer.
Do not turn grid-template-areas into ASCII art for its own sake.
Common placement mistakes
Hard-coded coordinates for dynamic lists
If content can be added, removed, filtered or sorted, explicit row/column coordinates often become brittle.
Prefer auto-placement and spans.
Using CSS visual order to fix HTML source order
Fix the markup first where possible.
Forgetting that explicit placement can create implicit tracks
A typo such as grid-column: 7 on a four-column grid can generate layout you never intended.
Using dense where sequence matters
Compact layout is not worth confusing keyboard/read order.
Naming everything
Semantic names are valuable. Fifty nearly identical line names in a small component are not automatically an improvement.
Reaching for absolute positioning for every overlap
If the layers belong to the same layout region, Grid overlap can be cleaner and preserve intrinsic sizing.
Debug placement systematically
When an item appears in the wrong cell, inspect these in order:
- What are the explicit row and column lines?
- Did the item create implicit tracks?
- Is it explicitly placed in one axis but auto-placed in the other?
- Does another item already occupy the target cells?
- Is
grid-auto-flowchanging placement behaviour? - Are negative lines referring to the explicit grid you actually defined?
- Is a responsive rule redefining
grid-template-areas? - Does the DOM order still make sense independently of the visual placement?
The browser’s Grid overlay will answer several of these instantly.
Pick the placement abstraction that survives change
Grid gives you precise control, but the best CSS is not necessarily the most explicit CSS.
A line number is good when geometry matters. A named line is good when the boundary has meaning. A named area is good when the page has recognizable regions. A span is good when an item needs more space but its exact location can remain automatic.
The goal is not to prove that you can control every cell.
It is to encode the layout’s intent in a form that still makes sense after content, breakpoints and components change.
In Part 3, we move into one of Grid’s most valuable modern features: subgrid — how nested components can finally align to parent tracks instead of each inventing their own almost-matching grid.
