CSS Grid
A two-dimensional CSS layout system that controls rows and columns simultaneously to build complex page shells and aligned grids
Table of Contents
Interactive Playground
Tap or drag to interact with the demoWhat is CSS Grid?
A two-dimensional CSS layout system that controls rows and columns simultaneously to build complex page shells and aligned grids. It is a core concept in Layout & Responsive within UI / UX.
Core Principles
CSS Grid Layout divides a container into two-dimensional row and column tracks so child elements can be positioned across exact cells or named regions. By combining fractional units (fr), minmax(), and repeat(auto-fit, minmax(240px, 1fr)), layouts adapt column counts fluidly without verbose media queries.
Features like grid-template-areas provide a readable visual map of the page shell, while subgrid allows nested elements inside cards to inherit and align with the parent grid's tracks.
Practical Takeaways
- Use Grid for macro shells, Flexbox for micro flows: Define dashboards, page skeletons, and multi-column galleries with CSS Grid, then align buttons, badges, and inline labels inside each cell with Flexbox.
- Guard against track blowout with
minmax(0, 1fr): Plain1frbehaves likeminmax(auto, 1fr), letting wide code blocks or tables stretch a column unexpectedly. Useminmax(0, 1fr)to keep columns strictly bounded. - Align uneven cards with
subgrid: When adjacent cards have different heading lengths,grid-template-rows: subgridaligns titles, descriptions, and footer actions horizontally across the entire row.
Notable Examples
- SaaS analytics dashboards: Combining 12-column tracks with variable
col-spanandrow-spanrules for KPI cards, charts, and activity feeds. - Intrinsic responsive product grids: Using
repeat(auto-fill, minmax(280px, 1fr))to flow smoothly from 1 column on phones to 4+ columns on desktop. - Editorial magazine layouts: Crafting asymmetric hero and sidebar compositions declaratively via
grid-template-areas.