Skip to content
Justice Tech School

Responsive Grids

repeat(auto-fit, minmax(150px, 1fr)) makes as many columns as fit, each at least 150px and sharing the leftover space. It needs no media queries. auto-fill is similar but keeps empty tracks.

grid-auto-rows sets the height of rows created automatically, and grid-auto-flow: dense lets small items fill earlier gaps.

Example
<style>
  .cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    grid-auto-rows: 70px;
    gap: 10px;
  }
  .cards div { background: #fecdd3; display: grid; place-items: center; border-radius: 8px; }
</style>
<div class="cards">
  <div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div>
</div>

Exercise

Each column must be at least 200px wide.

.g {
  grid-template-columns: repeat(auto-fit, (200px, 1fr));
}

Quiz Test

What does auto-fit do in repeat()?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.