Tracks, lines, cells and areas
Definition and purpose
Grid lays out items across rows and columns together. A track is the space between adjacent grid lines; a cell is the intersection of a row and column. An area is a rectangular group of cells.
Two-column inventory
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #p { width: 300px; } #p > div { background: lightblue; outline: 1px solid navy; } #p { display: grid; grid-template-columns: 100px 160px; grid-template-rows: 40px 50px; gap: 10px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>A and B occupy the first row; C occupies the second.
Syntax and mental model
display: grid creates a grid container. grid-template-columns and grid-template-rows define explicit tracks. With two columns there are three boundary lines, numbered from the start. Gaps separate tracks, not individual line numbers.
One explicit column
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> body { margin: 0; } #p { width: 300px; } #p > div { background: lightblue; outline: 1px solid navy; } #p { display: grid; grid-template-columns: 180px; grid-template-rows: 20px 30px 40px; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>Three rows share the one column; their heights differ.
Common mistakes
Do not count lines as cells. Also, explicit tracks may exist even if no item occupies them. In-flow direct children are grid items; nested descendants require their own layout.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Nested flex and baseline alignment. Next lesson: Fractional tracks and minmax.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Tracks, lines, cells and areas — knowledge check
Five questions on tracks, lines, cells and areas.
How many boundary lines enclose three explicit columns?
What is a cell?
Which property defines explicit row sizes?
Does a grid track need an item to exist?
What is a grid area?