CHAPTER 75

CSS Grid Responsive

Learn how CSS Grid can automatically adapt columns for different screen sizes.

01. What is CSS Grid Responsive?

Responsive Grid layouts change based on available space.
auto-fit and minmax can create flexible card layouts.
Media queries can also change the number of columns.

02. Syntax

grid-template-columns: repeat( auto-fit, minmax(220px, 1fr) );

03. Example

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

.grid {
    display: grid;

    grid-template-columns:
        repeat(
            auto-fit,
            minmax(220px, 1fr)
        );

    gap: 20px;
}

.card {
    padding: 30px;
    background: #dbeafe;
}

</style>
</head>
<body>

<div class="grid">

    <div class="card">HTML</div>
    <div class="card">CSS</div>
    <div class="card">JavaScript</div>
    <div class="card">PHP</div>

</div>

</body>
</html>

04. Important Points

✓ auto-fit can automatically fit available columns.
✓ minmax defines minimum and maximum track sizes.
✓ Grid can become responsive without many breakpoints.
✓ Always test content at narrow widths.

05. Common Mistakes

⚠ Choosing a minimum width that is too large.
⚠ Ignoring long text inside cards.
⚠ Testing only on desktop.

06. Real World Use

Responsive Grid is widely used for course cards, product grids, galleries and portfolio sections.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create an Auto-fit Card Grid

Create six cards using repeat(auto-fit, minmax(...)) and test them on mobile.