Introduction
In our last lesson, we completed our deep dive into Flexbox by mastering its alignment properties, solidifying your understanding of it as a powerful one-dimensional layout system. We established the core mental model of the main and cross axes, which gives you precise control over item positioning.
Now, we pivot to Flexbox's two-dimensional counterpart: CSS Grid. While Flexbox excels at distributing content in a single direction, Grid is designed for laying out content in both rows and columns simultaneously. Today's lesson focuses on a foundational concept that is critical to understanding how Grid works under the hood. Your learning outcome is to explain the difference between implicit and explicit grid tracks and when each is created.
Understanding this distinction is key to building robust and predictable layouts, especially when dealing with dynamic content where you don't always know how many items you'll need to display.
The Explicit Grid: The Blueprint
The most straightforward part of CSS Grid is the explicit grid. This is the grid that you, the developer, explicitly define in your CSS. You create this blueprint using the grid-template-columns and grid-template-rows properties.
.container {
display: grid;
grid-template-columns: 200px 200px 200px; /* 3 explicit columns */
grid-template-rows: 100px 100px; /* 2 explicit rows */
}
In this example, we have created an explicit 3x2 grid. We have defined a fixed number of tracks and their sizes.
To get the official definition and a clear starting point, let's turn to a well-regarded resource on this topic.
The Difference Between Explicit and Implicit Grids
The article 'The Difference Between Explicit and Implicit Grids' on CSS-Tricks provides a concise definition of what constitutes the explicit grid. This will give us a formal foundation to build upon.
Read the introductory paragraphs and the section titled 'Explicit Grids'. This will clearly define the term and the properties used to create an explicit grid.
The Implicit Grid: The Automatic Scaffolding
Things get more interesting when content or placement doesn't fit neatly into your explicit blueprint. In these cases, CSS Grid doesn't break; instead, it generates new grid tracks automatically to accommodate the content. These automatically created tracks form the implicit grid.
The W3C specification puts it this way, and understanding this definition is central to our goal.
Exploring CSS Grid's Implicit Grid and Auto-Placement Powers
Let's read a short excerpt from another CSS-Tricks article, 'Exploring CSS Grid's Implicit Grid and Auto-Placement Powers'. It quotes the official spec and provides an excellent 'plain English' translation.
Read the section titled 'Explicit, implicit? What the heck is going on here?'. Pay close attention to the quote from the specification and the author's summary.
As the article explains, the browser essentially auto-generates rows and columns when items are positioned outside the bounds you defined. There are two primary scenarios where this happens.
When are Implicit Tracks Created?
The browser creates implicit grid tracks in two main situations:
- Content Overflow: When you have more grid items than cells in your explicit grid.
- Explicit Placement: When you explicitly place an item on a grid line that doesn't exist in your explicit grid.
Let's watch a video that demonstrates both of these scenarios clearly.
The Explicit and Implicit grid explained
Kevin Powell's video, 'The Explicit and Implicit grid explained', is an excellent visual guide. We'll watch a few segments to see these concepts in action.
First, watch from 03:06 to 05:09. This part demonstrates the first scenario: how defining columns (grid-template-columns) causes the browser to create implicit rows automatically when there are more items than available columns. Note the effect of grid-auto-flow. Next, watch from 13:24 to 14:45. This part shows the second scenario: how explicitly placing an item outside the defined grid (e.g., grid-column: 6 on a 3-column grid) forces the browser to create implicit columns.
A great feature of modern browser developer tools is that they help you visualize this difference. Typically, explicit grid lines are shown as solid lines, while implicit grid lines are shown as dotted lines. This provides immediate feedback on what part of your grid was defined by you and what part was automatically generated. Kevin Powell briefly points this out in his video (at 07:48).
Here is a static image that summarizes the concept well:

Taking Control: Sizing Implicit Tracks
By default, implicit tracks are sized automatically (auto), meaning they grow just large enough to fit their content. For a developer who wants to understand the underlying mechanics and maintain control, this might not be ideal.
Fortunately, CSS Grid provides two properties specifically for controlling the size of these automatically created tracks:
grid-auto-rowsgrid-auto-columns
These properties allow you to define a size or a sizing pattern for any tracks that are created in the implicit grid. This is a crucial part of the grid algorithm.
The Explicit and Implicit grid explained
Let's return to Kevin Powell's video. He provides a thorough demonstration of how to use grid-auto-rows and grid-auto-columns to control the implicit grid.
Watch from 14:45 to 18:43. Observe how he uses grid-auto-columns to set the size of implicitly created columns, and grid-auto-rows to do the same for rows. This demonstrates how you can move from a default, content-based size to a predictable, defined size for any part of your grid.
This ability to pre-define the behavior of an automatically generated grid is what makes the system so powerful and robust. You can create layouts that are both strictly defined and flexible enough to handle unexpected content gracefully.
A Practical Example: The Dynamic Sidebar
Let's see how this concept applies to a practical scenario. Imagine a layout where a sidebar might or might not be present. Using the implicit grid, we can make the layout adapt automatically.
Exploring CSS Grid's Implicit Grid and Auto-Placement Powers
The article 'Exploring CSS Grid's Implicit Grid...' provides a perfect 'Dynamic sidebar' example that showcases the power of this concept.
Read the section titled 'Dynamic sidebar'. Notice how the grid is initially defined with only one explicit column. When the <aside> element is added and placed in column 2, the browser creates an implicit second column for it. This is a very practical use case for implicit grid creation.
This example highlights the "why" behind the implicit grid. It's not just a fallback mechanism; it's a feature that enables dynamic and intelligent layouts with minimal CSS.
Conclusion
In this lesson, we dissected the foundational difference between the explicit and implicit grid systems. Understanding this distinction is not just academic; it is fundamental to predicting, debugging, and harnessing the full power of CSS Grid.
Key Takeaways:
- Explicit Grid: The grid tracks you define using
grid-template-columnsandgrid-template-rows. This is your intended blueprint. - Implicit Grid: The grid tracks the browser automatically generates when content or placement extends beyond the explicit grid. This is the automatic scaffolding.
- Creation Triggers: Implicit tracks are primarily created in two scenarios: when there are more items than available cells, or when an item is explicitly placed outside the defined grid boundaries.
- Sizing Control: By default, implicit tracks are auto-sized to their content. You can and should take control of their dimensions using the
grid-auto-rowsandgrid-auto-columnsproperties for predictable layouts.
What's Next?
Now that you understand how Grid creates its tracks, the next logical step is to explore how it distributes space within those tracks. In the next lesson, we will dive into one of Grid's most powerful features: the fr unit. You will learn how the fr unit functions and how the grid algorithm distributes fractional space, allowing you to create flexible, proportional layouts with ease.