Lesson 20 of 55
HTMLCSS Grid Layout
11 min
Course progress36%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 20 of 55
HTML11 min
Keep these ideas in mind as you work through the lesson.
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr); /* three equal columns */
grid-gap: 1rem; /* spacing between tracks */
}
grid-template-columns / grid-template-rows define tracks (columns and rows).grid-column / grid-row place items.fr unit distributes free space proportionally.<div class='grid'>
<div class='card'>…</div>
<div class='card'>…</div>
<div class='card'>…</div>
</div>
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1.5rem;
}
auto-fill creates as many columns as will fit, each at least 200 px wide. Empty tracks collapse automatically.
grid-template-areas – Named layout regions for easier reading.align-items, justify-items – Align content inside each grid cell.subgrid (future) – Allows a child grid to inherit the parent’s column definition.display:grid? ✅fr, minmax, or explicit pixel values? ✅gap, row-gap, column-gap)? ✅grid-column/grid-row where needed? ✅Tip: Pair
auto-fillwithminmaxfor truly fluid, responsive grids that adapt to any screen size.