CSS Grid is a two-dimensional layout system. It allows you to align content into rows and columns simultaneously, giving you total control over the web page structure.
The fr unit represents a fraction of the free space in the grid container. It is much better than using percentages because it handles gaps automatically.
| Property | Description |
|---|---|
| grid-template-columns | Defines column widths (e.g., 1fr 1fr 1fr). |
| repeat(n, size) | Helper function to avoid typing same values (e.g., repeat(3, 1fr)). |
| place-items | Shorthand to center items both vertically & horizontally (e.g., center). |
| gap | Controls the spacing between rows and columns. |
One of the most powerful features of Grid is creating responsive layouts without media queries. The example below uses auto-fit.
Using grid-template-areas makes your CSS readable. You can literally "draw" your layout in the code.