Grid Areas & Dynamic Functions
Draw your layouts using ASCII art, and learn the 'Holy Grail' of responsive grids: auto-fit with minmax().
What it is
While placing items by line numbers is precise, CSS Grid offers two even more powerful techniques: **Grid Template Areas** (for visual mapping) and **Dynamic Grid Functions** like repeat(), auto-fit, and minmax() (for automatic responsiveness).
Why it matters
If you've ever tried to build a responsive card grid using Flexbox, you know the pain of calculating widths and margins. With CSS Grid functions, you can create a perfectly wrapping, responsive grid of cards without writing a single Media Query.
Meanwhile, Grid Areas allow you to completely rearrange the layout of a complex component just by rewriting a single string of text in the parent container.
How it works
1. **Grid Areas**: You assign a name to a child item using grid-area: header;. Then, on the parent container, you literally draw the layout using strings: grid-template-areas: 'header header' 'sidebar main' 'footer footer';.
2. **minmax()**: A function that sets a flexible size range. minmax(200px, 1fr) means 'never shrink smaller than 200px, but grow up to 1fr to fill leftover space'.
3. **The Holy Grail**: grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));. This magical line tells the browser: 'Fit as many 200px columns as you can on this row. If there's leftover space, let them stretch (1fr). If a column can't fit, automatically bump it to the next row!'
Try it
Drag the resize handle to change the container's width. Watch how auto-fit combined with minmax() automatically recalculates the number of columns and reflows the grid!
Grid Magic: auto-fit & areas
Concept Explorer
Container Width
Drag the slider to shrink the container. Watch columns wrap automatically.
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
Remember this
grid-template-areaslets you visually draw your layout using strings.minmax(min, max)sets flexible boundaries for a track's size.repeat(auto-fit, ...)creates automatic responsiveness without media queries.- Named grid areas must always form perfect rectangles.
Done with this concept?
Mark it complete to track your progress. No login needed.