Course contentsShow
← Web Development
Lesson 349 of 2,9826. CSS GridFree lesson

Named Grid Lines

Assigning names to grid lines in the template definition for semantic placement.

Named Grid Lines

What you'll learn: How to give meaningful names to your grid lines so you can place items using semantic, readable labels instead of just numbers.

Why Name Your Grid Lines?

You've already learned that grid lines are numbered automatically (1, 2, 3, etc.). But when building complex layouts, remembering which line number represents "sidebar-end" or "content-start" can get confusing. Named grid lines let you assign custom names directly in your grid-template-columns or grid-template-rows definitions.

How Named Grid Lines Work

You define names by wrapping them in square brackets [name] within your grid template. These names appear between track sizes, marking the line at that position.

.grid-container {
  display: grid;
  grid-template-columns: [sidebar-start] 200px [sidebar-end content-start] 1fr [content-end];
  grid-template-rows: [header-start] 80px [header-end main-start] 1fr [main-end];
}

Notice how each line can have multiple names (like [sidebar-end content-start]). This is helpful when one line serves as both the end of one region and the start of another.

Using Named Lines for Placement

Once named, you can reference these lines when positioning items:

.header {
  grid-column: sidebar-start / content-end;
  grid-row: header-start / header-end;
}

.sidebar {
  grid-column: sidebar-start / sidebar-end;
  grid-row: main-start / main-end;
}

This reads much more clearly than grid-column: 1 / 3 — you immediately understand what you're positioning, not just where.

Key Takeaway: Named grid lines let you replace numeric line references with semantic labels in your grid-template-columns and grid-template-rows definitions, making your grid placement code self-documenting and easier to maintain.