CSS · Layout and visual systems
How does CSS Grid work?
Short answer
Grid is a two-dimensional layout system. You define rows and columns, then place items into cells, spans or named areas, with fr units and minmax controlling track sizing.
A grid container establishes explicit tracks with grid-template-columns and grid-template-rows. Items can be placed automatically, by line numbers, by named areas, or by spans. Extra items create implicit tracks if needed.
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
gap: 1.5rem;
}
.page {
display: grid;
grid-template-areas:
"header header"
"sidebar main";
grid-template-columns: 16rem 1fr;
gap: 1rem;
}Core concepts
- fr distributes free space after fixed track sizes are resolved
- minmax(min, max) sets a track's size range
- repeat(auto-fit, ...) collapses empty tracks; auto-fill keeps them
- grid-template-areas names regions for readable placement
- grid-auto-rows and grid-auto-columns size implicit tracks
- gap spaces tracks without margins
Grid is layout-in: the container defines the structure and items are placed into it. Items can also overlap by occupying the same cells, which is useful for layered hero sections when done intentionally.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1What is the difference between auto-fit and auto-fill?
- 2How does the fr unit resolve track sizes?
- 3What creates an implicit grid track?
- 4How do named grid areas work?
Say it in the interview
Grid is two-dimensional. I define columns and rows, then place items by line, span, or named area. The fr unit distributes leftover space, and minmax plus repeat auto-fit gives responsive card layouts without media queries. Grid is layout-in because the container defines the structure, and items can overlap intentionally while implicit tracks handle anything outside the explicit grid.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CSS mock interview and get scored feedback on depth, clarity and confidence.