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

Grid Lines and Line Numbers

Understanding how grid lines are numbered and how they define the boundaries of grid tracks.

Grid Lines and Line Numbers

You'll learn: How CSS Grid uses numbered lines to define the edges of rows and columns, giving you precise control over item placement.


What Are Grid Lines?

When you create a grid with grid-template-columns and grid-template-rows, CSS automatically creates grid lines—invisible boundaries that separate the tracks (rows and columns). Think of them like the ruled lines on graph paper: the squares are your grid cells, and the lines around them have numbers you can reference.

How Grid Lines Are Numbered

Grid lines are numbered starting from 1, not 0. For a three-column grid:

  • Line 1 is the far left edge
  • Line 2 separates column 1 and column 2
  • Line 3 separates column 2 and column 3
  • Line 4 is the far right edge

Notice that three columns create four vertical lines. The same logic applies to rows: three rows create four horizontal lines.

.grid {
  display: grid;
  grid-template-columns: 100px 200px 100px;
  /* Creates vertical lines 1, 2, 3, and 4 */
}

Counting from the End

You can also count backwards using negative numbers. Line -1 is always the last line (far right for columns, bottom for rows), -2 is second-to-last, and so on. This is incredibly useful for spanning items to the end of the grid without knowing the exact column count.

Why This Matters

These line numbers are the foundation for placing items precisely in your grid. Instead of letting items flow automatically, you'll soon use these numbers to say "start at line 2 and end at line 4." Your browser's DevTools grid inspector actually shows these numbers overlaid on your grid!

Key Takeaway: Grid lines are numbered boundaries between tracks, starting at 1 from the start and -1 from the end, forming the coordinate system for precise grid item placement.