CSS Academy · Lesson

Auto-fit and Auto-fill with minmax

Create responsive column counts automatically using auto-fit and auto-fill with minmax().

Lesson 2 of 413 steps

Auto-fit and Auto-fill with minmax is a free CSS Academy lesson on CoddyKit. This is lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the CSS Academy learning path, and your progress syncs across the web and the CoddyKit app. The CSS Academy course includes 4 lessons in total.

The Auto-Responsive Grid

The most powerful CSS Grid pattern: a fully responsive grid that adjusts column count automatically without any media queries, using auto-fit or auto-fill combined with minmax().

auto-fill

auto-fill fills the row with as many columns as it can fit at the given minimum size. Empty columns are preserved as empty tracks at the end.

  <div class="grid">
    <div>1</div><div>2</div><div>3</div><div>4</div>
  </div>

auto-fit

auto-fit works like auto-fill but collapses empty tracks to zero width. Existing items stretch to fill the remaining space.

  <div class="grid">
    <div>1</div><div>2</div><div>3</div>
  </div>

auto-fill vs auto-fit Difference

The difference only matters when there are fewer items than can fill the row:

  • auto-fill: empty column tracks remain, items do not stretch to fill
  • auto-fit: empty tracks collapse, items expand to fill all available width

auto-fit with minmax()

The famous responsive grid pattern — items are at least 250px wide, grow to fill space, and wrap to new rows automatically:

  <div class="responsive-grid">
    <div>Card 1</div><div>Card 2</div><div>Card 3</div>
  </div>

minmax() Explained

minmax(min, max) defines a track size range. The track will not be smaller than min or larger than max. Combined with fr, it creates flexible tracks bounded by a minimum.

  <div class="track"><div>Flexible track</div></div>

auto-fill with minmax for Fixed Items

When you want items at a fixed size and allow empty space at the end:

  <div class="icon-grid">
    <div>&#128295;</div><div>&#9881;</div><div>&#128296;</div>
  </div>

Responsive Without Media Queries

This is the main benefit: repeat(auto-fit, minmax(280px, 1fr)) automatically adapts from 1 column on mobile to as many columns as fit on larger screens:

  <div class="cards">
    <div>Card A</div><div>Card B</div>
  </div>

min() for Safer minmax

Avoid layout issues in tiny containers by using min(100%, 280px) as the minimum instead of a raw pixel value:

  <div class="grid"><div>Item</div></div>

auto-fill for Masonry-Like Alignment

With auto-fill, empty tracks at the end maintain alignment when items count is not a multiple of columns — useful for consistent grids.

Grid Intrinsic Sizing vs Flexbox

Flexbox flex-wrap + flex: 1 1 250px is similar but does not guarantee equal column widths — items may stretch unevenly. Grid with minmax ensures perfectly uniform tracks.

Quick Check

Which grid value creates responsive columns without media queries by collapsing empty tracks so items fill available space?

Recap

repeat(auto-fit, minmax(250px, 1fr)) is the single most powerful responsive grid pattern — zero media queries needed. auto-fit collapses empty tracks so items fill the row. auto-fill preserves empty tracks for consistent alignment. Always pair with gap for gutters.

Free to start

Learn CSS with an AI tutor — free

Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.

Courses
40
Lessons
159

Frequently Asked Questions

Is the “Auto-fit and Auto-fill with minmax” lesson free?

Yes — the full text of “Auto-fit and Auto-fill with minmax” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the CSS Academy course, upgrade to CoddyKit PRO. The CSS Academy course includes 4 lessons in total.

What will I learn in “Auto-fit and Auto-fill with minmax”?

Create responsive column counts automatically using auto-fit and auto-fill with minmax(). You practise CSS Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start CSS Academy?

No prior experience is required. CSS Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 4.

How long does the “Auto-fit and Auto-fill with minmax” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this CSS Academy lesson?

Yes. Every CSS Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Named Lines and Named Grid Areas
  2. Auto-fit and Auto-fill with minmax
  3. Implicit Grid and Grid-Auto-Flow
  4. Subgrid for Aligned Nested Content
← Back to CSS Academy