Menu
Box Model & Layout
CSS Grid
Two-dimensional layouts with rows and columns.
1Grid Container
Set display: grid and define columns/rows with grid-template-columns / grid-template-rows.
Example Code
.grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 16px;
}2fr Unit & Auto
fr is a fractional unit of available space. Use auto for content-sized tracks.
Example Code
.grid {
display: grid;
grid-template-columns: 200px 1fr 1fr;
}3Grid Areas
Name areas to build complex layouts in a readable way.
Example Code
.layout {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 200px 1fr;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }4Auto-fit & minmax
Build responsive grids without media queries.
Example Code
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
gap: 20px;
}Finished reading?
Mark this topic as complete to track progress.