FrontendCSSGridLayoutFrontend

CSS Grid Layout: Build Any Layout You Can Imagine

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

Abdur Razzak

Abdur Razzak

Full-Stack Web Developer

June 15, 2025 10 min read

Grid vs Flexbox

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.

Defining a Grid

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.

Placing Items

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.

Named Grid Areas

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.

Share this article

All posts
#CSS#Grid#Layout#Frontend
Abdur Razzak — Full Stack Web Developer

Let's Connect

Follow My Developer Journey