← Back to Learning Path Level 1 • Lesson 1 of 3
Level 1 progress 0% complete

Lesson 1: What is CSS Grid?

Learn the fundamentals of CSS Grid and why it changes the way you build layouts.

What is CSS Grid?

CSS Grid is a layout system that lets you build two-dimensional layouts with rows and columns. Think of it like a spreadsheet for your webpage: you define a grid structure, then place content into the cells.

Before CSS Grid, developers used floats, positioning, and Flexbox to create layouts. These methods work, but they were never designed specifically for page layouts. CSS Grid was built from the ground up to solve layout problems, making it more intuitive and powerful.

Why Use CSS Grid?

1. Two-Dimensional Layouts

Unlike Flexbox, which is one-dimensional, CSS Grid lets you control both rows and columns at the same time. This makes complex layouts much easier to build and maintain.

2. Less Code

What used to take dozens of lines of CSS with floats or positioning can now be done in just a few lines with Grid. Your code becomes cleaner and easier to understand.

3. Responsive by Design

CSS Grid has built-in features for responsive design. You can create layouts that automatically adapt to different screen sizes without writing complex media queries.

The Basic Concept

Every CSS Grid layout has two key parts:

Key Concept When you set display: grid on a container, all its direct children automatically become grid items. You do not need to do anything special to the children.

Your First Grid

Here is the simplest possible grid:

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 20px;
}

This creates:

Try It Yourself The best way to understand Grid is to experiment. Use the Gridlock Holmes generator to create your first grid and see how it works.

Common Use Cases

CSS Grid is well suited for:

Grid vs. Other Methods

When to use Grid: When you need to control both rows and columns, or when you are building a page layout.

When to use Flexbox: When you are arranging items in a single direction, like a navigation bar or a row of buttons.

The truth: You will often use both. Grid for the overall page structure, Flexbox for components within the grid.

Browser Support

CSS Grid is supported in all modern browsers, including Chrome, Firefox, Safari, and Edge, and works in over 96% of browsers worldwide. For older browsers such as IE11, you will need fallback layouts, but for most projects, Grid is safe to use today.

Next Steps

Now that you understand what CSS Grid is and why it is useful, you are ready to learn how to actually use it. In the next lesson, we will cover rows, columns, and how to create your first practical grid layout.

Practice Time

Before moving on, try creating a simple 3-column grid using the Gridlock Holmes generator. Experiment with different column sizes and gap values to see how they affect the layout.

Open Generator

Quick Check

Test your knowledge before moving to the next lesson. All 3 questions must be correct to continue.

1. What property turns a div into a grid container?

2. What makes CSS Grid different from Flexbox?

3. What are the two key parts of every CSS Grid layout?

← Previous