Course contentsShow
← Web Development
Lesson 311 of 2,9826. CSS GridFree lesson

Enabling Grid: display: grid

How to create a grid container and the immediate effects on direct children becoming grid items.

Enabling Grid: display: grid

What you'll learn: How to activate CSS Grid on an element and what instantly happens to its children.


Creating a Grid Container

Just like you enable Flexbox with display: flex, you activate CSS Grid by applying display: grid to a container element. This single declaration transforms that element into a grid container and its direct children automatically become grid items.

.container {
  display: grid;
}

The Immediate Effect

When you write display: grid, here's what happens instantly:

  1. The container becomes a grid context – it now uses Grid layout rules instead of normal flow
  2. Direct children become grid items – each child is placed into the grid system
  3. A single-column grid is created by default – without additional instructions, items stack vertically in one column (similar to normal block layout)
<div class="container">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>
.container {
  display: grid;
  /* Without defining columns/rows, you get 1 column by default */
}

At this point, it looks almost identical to regular block layout – items still stack vertically. The magic comes when you define your grid structure (which you'll learn next).

Think of It Like This

Imagine spreading a blank sheet of graph paper over your container. Right now it's invisible with just one column, but you've enabled the grid system. You're ready to draw lines and create your layout structure.

Key Takeaway: display: grid transforms an element into a grid container, making its direct children grid items that are ready to be positioned within a grid structure (even though by default they'll stack in a single column).