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:
- The container becomes a grid context – it now uses Grid layout rules instead of normal flow
- Direct children become grid items – each child is placed into the grid system
- 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).