CSS Grid Layout Tutorial

A complete beginner-to-advanced guide to modern layout with CSS Grid — rows, columns, responsive layouts and examples.

A complete beginner-to-advanced guide to mastering modern layout design.

Introduction

CSS Grid is one of the most powerful layout systems ever added to CSS. Before Grid, developers struggled with floats, hacks, nested divs, and endless media queries.

In this tutorial, you'll learn exactly how CSS Grid works — with examples you can use instantly.

1. What is CSS Grid?

CSS Grid is a layout system that lets you define:

This immediately creates a 3-column layout with spacing.

2. Creating Your First Grid Container

Now you choose how many columns/rows you want.

Fixed Columns:

Responsive Columns:

3. Defining Rows and Columns

Columns

Rows

Example Using minmax():

4. Grid Gaps (No More Margin Hacks)

5. Placing Items on the Grid

Span Shortcut

Real Example:

6. Creating Responsive Layouts with CSS Grid

Method 1: Auto-Fit + Minmax

This is the most powerful responsive pattern:

Method 2: Media Queries (Optional)

7. Aligning Items in Grid

Align Items Vertically

Align Items Horizontally

Align Whole Grid Content

Align Individual Items

8. Template Areas (Most Beginner-Friendly Feature)

You can visually draw your layout using names:

CSS:

This makes layout code readable like a wireframe.

9. Complete Example: Modern Responsive Dashboard

This is similar to many modern admin dashboards — easy to build with Grid.

10. CSS Grid vs Flexbox — When to Use Each?

Feature

Use CSS Grid

Use Flexbox

2D layout (rows + columns)

✔ YES

✖ NO

1D layout (row or column)

Complex page structure

Navigation bars

Full-page layout

Aligning items on one axis

11. Common CSS Grid Mistakes

Follow modern patterns and Grid becomes insanely powerful.

12. Summary

CSS Grid is one of the best tools in modern front-end development. Practice building layouts and you'll become faster, cleaner, and more professional in your web design.

Related articles