CHAPTER 72

CSS Grid Container

Learn how grid-template-columns, rows, gap and alignment control the grid container.

01. What is CSS Grid Container?

The grid container controls rows and columns.
Grid properties define track sizes and spacing.
Grid can create highly structured responsive layouts.

02. Syntax

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

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>

.grid {
    display: grid;
    grid-template-columns:
        200px 1fr 200px;
    grid-template-rows:
        auto;
    gap: 20px;
}

.item {
    padding: 25px;
    background: #2563eb;
    color: white;
}

</style>
</head>
<body>

<div class="grid">

    <div class="item">Sidebar</div>
    <div class="item">Main</div>
    <div class="item">Right</div>

</div>

</body>
</html>

04. Important Points

✓ grid-template-columns controls column tracks.
✓ grid-template-rows controls row tracks.
✓ gap controls spacing.
✓ fr units are useful for flexible tracks.

05. Common Mistakes

⚠ Using too many fixed columns.
⚠ Creating layouts that cannot shrink.
⚠ Ignoring content size.

06. Real World Use

Grid containers are useful for dashboards, admin panels, websites and card-based layouts.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Grid Layout

Create a layout with a 200px sidebar, flexible main area and 200px right column.