What Is CSS Grid?
CSS Grid arranges items in rows and columns at the same time. It is ideal for whole page layouts, galleries and dashboards.
The fr Unit
fr means a fraction of the free space. 1fr 2fr 1fr makes the middle column twice as wide as the others. You can mix units: 250px 1fr is a fixed sidebar plus a flexible main area.
repeat, minmax and auto-fit
Meaning: make as many columns as fit, each at least 14rem and sharing leftover space equally. The gallery goes from 1 column on phones to 4 or more on large screens, without any media query.
Placing and Spanning Items
Named Areas: Page Layout
The layout is drawn right in the CSS. On small screens we redraw it as a single column.
Alignment
| Property | Effect |
|---|---|
justify-items, align-items | Align items inside their cells |
justify-content, align-content | Align the whole grid inside the container |
place-items: center | Shorthand to center items in cells |
grid-auto-rows: minmax(8rem, auto) | Size for rows you did not define |
subgrid lets nested items line up with the parent grid. It is now supported by the major browsers, but check a support table such as MDN or Can I Use before relying on it for older devices.
Practice
- Build the page layout with header, nav, main, aside and footer
- Create a photo gallery with auto-fit and minmax
- Make one featured item span two columns
Conclusion
Grid controls rows and columns together. Use fr units, auto-fit with minmax for responsive galleries and named areas for page layouts.

