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

Grid with Named Lines

Use custom line names to create semantic grid placements and reusable layout patterns.

Grid with Named Lines

You'll learn: How to use custom line names to make your grid layouts more readable, maintainable, and semantically meaningful.

What Are Named Lines?

Instead of using numbers like 1, 2, 3 to reference grid lines, you can give them meaningful names. Think of it like labeling the edges of a picture frame: rather than saying "the third edge," you can say "the left edge" or "the right edge." This makes your code self-documenting and easier to understand months later.

Naming Lines in Your Template

You define named lines inside square brackets when creating your grid template:

.container {
  display: grid;
  grid-template-columns: 
    [sidebar-start] 250px 
    [sidebar-end content-start] 1fr 
    [content-end];
}

Here, you've named the lines sidebar-start, sidebar-end, content-start, and content-end. Notice that a single line can have multiple names!

Using Named Lines for Placement

Now you can place items using these semantic names:

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

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

This is far clearer than grid-column: 1 / 2 and grid-column: 2 / 3. Your code explains what the layout represents, not just where things are positioned.

Creating Reusable Patterns

Named lines shine when you're building consistent layouts. You can define semantic regions like [header-start], [main-start], [footer-start] and then place items using those names across your entire site.

Key Takeaway: Named grid lines replace numeric line references with meaningful labels, making your grid layouts self-documenting and easier to maintain as your project grows.