Skip to content
tezvyn:

Using CSS Grid, how do repeat, auto-fit, and minmax create responsive columns?

Source: developer.mozilla.orgHardHow cards are made

Using CSS Grid, how do repeat, auto-fit, and minmax create responsive columns?

Tests intrinsic sizing and responsive tracks without media queries. A strong answer gives repeat(auto-fit, minmax(250px, 1fr)), noting repeat generates tracks, auto-fit collapses empties, and minmax sets a floor with fractional growth.

What's really being asked

This tests whether you understand intrinsic web design and CSS Grid track sizing beyond basic property names. Interviewers want to see that you can build responsive layouts without relying solely on media queries, that you grasp how the browser distributes leftover space, and that you know the precise difference between auto-fit and auto-fill behavior when tracks outnumber items.

The full answer

First, the exact declaration: grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)). Second, the role of repeat: it generates a repeated track pattern so you do not hardcode individual column values. Third, minmax: it sets a hard or soft floor, usually in pixels or ch units, and pairs it with a flexible upper bound like 1fr so cards never shrink below the minimum but share extra space equally. Fourth, auto-fit: it instructs the grid to collapse any empty repeated tracks down to zero width, which causes the remaining items to expand and fill the entire row. Fifth, the absence of media queries: the layout automatically reflows from four columns to three to two to one as the viewport narrows because the browser drops tracks that can no longer satisfy the minmax minimum.

The mistakes people make

A common wrong answer is suggesting auto-fill instead of auto-fit without noting that auto-fill preserves empty tracks, leaving invisible gaps at the end of a row rather than stretching the actual cards. Another red flag is proposing media queries to change grid-template-columns at breakpoints, which defeats the purpose of the question and shows unfamiliarity with intrinsic sizing. Some candidates also misuse minmax by setting both values to fixed lengths, which prevents the responsive expansion the interviewer is looking for.

What usually comes next

An interviewer might ask how to cap the maximum width of cards so they do not become unwieldy on ultra-wide screens; the answer is to wrap the grid in a max-width container or switch to minmax with a clamp. They might also ask about the dense keyword if the card heights vary, or how to handle uneven content without misalignment. Another follow-up is browser support and fallbacks for older environments.

A concrete example

Imagine a product listing page where each card needs at least 280 pixels but should grow to fill the screen. You would write grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; on the container. On a 1440 pixel monitor, you get four columns. On a tablet, you get two. On mobile, one. No media queries are required for the column count because the browser removes tracks that violate the 280 pixel minimum and redistributes space via the 1fr upper bound.

Interview question

A developer notices unwanted invisible gaps at the end of rows when using grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)). Which single change fixes this while keeping the layout responsive?

  • a.Apply justify-content: space-between to the container
  • b.Replace minmax with clamp(250px, 100%, 400px)
  • c.Replace auto-fill with auto-fitCorrect
  • d.Replace 1fr with a fixed maximum like 300px
Why?

auto-fit collapses empty repeated tracks to zero width, causing the remaining items to expand and fill the row, while auto-fill preserves invisible tracks at the end of the row. Replacing 1fr with a fixed maximum would prevent responsive expansion and would not remove the empty track gaps.

Just read this? Test yourself on what you have been reading.

Read the original → developer.mozilla.org

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.

See open roles