CSS Grid is the most powerful layout system in CSS. This guide covers everything from basics to complex multi-area layouts.

Abdur Razzak
Full-Stack Web Developer
Flexbox is one-dimensional — it works along a single row or column. CSS Grid is two-dimensional — you define rows and columns simultaneously. Use Flexbox for components like navigation bars or card rows; use Grid for page-level layouts.
Set display:grid on a container, then define columns with grid-template-columns. For example, grid-template-columns: repeat(3, 1fr) creates three equal-width columns. The fr unit distributes available space proportionally.
Grid items are placed automatically by default. You can override placement with grid-column and grid-row, specifying start and end lines. Negative values count from the end, so grid-column: 1 / -1 always spans the full width.
Grid template areas let you name regions and assign items to them with grid-area. This makes complex layouts readable and maintainable — you can see the entire layout structure at a glance in the parent container.