Implicit tracks and auto-placement
Definition and purpose
Grid creates implicit tracks when placed items need space beyond the explicit template. Auto-placement fills available positions using the flow algorithm, and implicit track sizing controls the new rows or columns.
Create an implicit row
<!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 100px; grid-template-rows: 25px; grid-auto-rows: 45px; 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>C creates a second row with the implicit height of 45px.
Syntax and mental model
grid-auto-rows: 40px sizes implicit rows. grid-auto-flow: row normally moves through rows; column uses columns. Adding dense can fill earlier holes with later items that fit, changing visual order compared with the sparse algorithm.
Fill a hole densely
<!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: repeat(3, 100px); grid-auto-rows: 30px; grid-auto-flow: row dense; } #a, #b { grid-column: span 2; } </style> </head> <body> <div id="p"> <div id="a">A</div> <div id="b">B</div> <div id="c">C</div> </div> </body></html>C fills the hole left by A, even though C follows B in source order.
Common mistakes
Avoid dense placement for ordered interactive content. Implicit tracks do not automatically inherit the sizes of explicit tracks; specify grid-auto-rows or grid-auto-columns when appropriate.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Explicit placement and named areas. Next lesson: Responsive auto-fill and auto-fit.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Implicit tracks and auto-placement — knowledge check
Five questions on implicit tracks and auto-placement.
What creates an implicit track?
What sizes additional implicit rows?
What is the default auto-flow direction?
What can dense packing change?
Why avoid dense for ordered controls?