CSS Grid Layout System

Build a responsive grid layout system using CSS Grid with auto-fit and minmax for flexible column counts.

CssConfig Management

Code

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
}

CSS Grid Layout System

Build a responsive grid layout system using CSS Grid with auto-fit and minmax for flexible column counts.

Code

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 1rem;
}

Explanation

auto-fit with minmax lets the grid decide the column count from the available width, so cards reflow without media queries. Expected behavior: columns expand to fill the row and leftover tracks collapse. Caveat: auto-fit collapses empty tracks while auto-fill keeps them, which changes spacing when there are few items.

Interactive Tools for This Topic