CSS Grid defines rows and columns at once—ideal for page shells: sidebar + content, photo galleries, dashboards.
Starter template
.layout {
display: grid;
grid-template-columns: 1fr 3fr;
gap: 1.5rem;
}
Responsive grid
Use repeat(auto-fit, minmax(12rem, 1fr)) for card galleries that reflow without manual breakpoints.
Practice
- Change column ratio to
240px 1frfor a fixed sidebar. - Add a third row spanning both columns with
grid-column: 1 / -1.
Important interview questions and answers
- Q: Grid vs Flexbox?
A: Grid for 2D layouts; Flex for 1D distribution and alignment. - Q: What does `fr` mean?
A: A flexible fraction of free space in the grid track. - Q: How do you span columns?
A: `grid-column: 1 / -1` or `span 2` depending on track setup.