CSS Grid
7 min read Quiz at the end
CSS Grid creates two-dimensional layouts. Set display: grid and define columns with grid-template-columns: repeat(3, 1fr). gap adds space between all cells. Items span multiple columns with grid-column: span 2.
CSS Grid .container {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 equal cols */
grid-template-rows: auto 1fr auto; /* header/main/footer */
gap: 24px;
}
/* Named areas */
.container {
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
Topic Quiz · 5 questions
Test your understanding before moving on
1. grid-template-columns: repeat(3, 1fr) creates:
A. 3 rows
B. 3 equal-width columns
C. A 3x3 grid
D. 3 fixed columns
💡 repeat(3, 1fr) creates 3 columns each taking 1 fraction of available space.
2. What does gap do?
A. Padding inside cells
B. Space between grid rows and columns
C. Border between cells
D. Outer margin
💡 gap sets the gutter space between rows and columns in Grid (and Flexbox).
3. grid-area is used with:
A. grid-template-areas
B. grid-column
C. grid-row
D. All of the above
💡 grid-area names a grid item for placement with grid-template-areas.
4. auto-fill vs auto-fit?
A. Same
B. auto-fill keeps empty columns; auto-fit collapses them
C. auto-fit is deprecated
D. auto-fill is faster
💡 auto-fill keeps empty tracks; auto-fit collapses them so items expand to fill space.
5. Which creates a responsive grid without media queries?
A. grid-template-columns: auto
B. repeat(auto-fill, minmax(250px, 1fr))
C. display: flex; flex-wrap
D. grid: auto-responsive
💡 repeat(auto-fill, minmax(250px, 1fr)) creates a responsive multi-column grid automatically.
Submit answers