CSS Grid
A CSS layout mode that places a container's children into rows and columns.
In more detail
Like flexbox, grid only positions direct children, so wrapper elements get in the way. Do not confuse it with the 8-point spacing grid, which is a spacing rule rather than a CSS feature.
Example
In the browser: You define tracks with grid-template-columns and grid-template-rows, optionally name regions with grid-template-areas, and place items into them. Flexbox handles one direction; grid handles both, and the two are often combined.Related terms
- Flexbox — A CSS layout mode that arranges a container's children in a row or column and distributes space between them.
- 8-point grid — A spacing rule where every margin, padding and component size is a multiple of 8 pixels, with 4 pixels allowed for tight spots.
- grid track — One row or one column of a CSS grid, the space between two neighbouring grid lines.
- grid-template-areas — The CSS Grid property that names regions of the grid with a visual text map, such as "header header" "sidebar main", so items can be placed by name.
- fr unit — A CSS Grid unit meaning one share of the space left after fixed-size tracks and gaps have been taken out.
- minmax() — A CSS Grid function that lets a track size vary between a minimum and a maximum, such as minmax(280px, 1fr).
- subgrid — A CSS Grid value that lets a nested grid use its parent grid's tracks instead of sizing its own, so content in separate cards lines up.
Taught in
- Polymorphism & Slotted Composition: The asChild Pattern — Design Systems & Component Engineering
- Modern Box Model, Box Sizing, Display Types And Flow Layout — Frontend Architecture & Web Platform
- Advanced CSS Grid: Named Areas, minmax And auto-fit — Frontend Architecture & Web Platform
- CSS Subgrid: Inheriting Track Sizing Across Nested Layouts — Frontend Architecture & Web Platform