# Responsive Auto Grid

> A grid that adds and removes columns on its own. No media queries needed.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: grid, responsive, auto-fit, minmax, cards
- Live preview: https://copy-css.com/snippets/responsive-auto-grid
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="auto-grid">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>
```

## CSS

```css
.auto-grid {
  --min: 220px; /* smallest a column may get */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, var(--min)), 1fr));
  gap: 16px;
}
```

## Notes

- This CSS Responsive Auto Grid is 6 lines of pure CSS (0.2 KB) with no JavaScript and no dependencies. It uses CSS Grid and custom properties.
- Customize with: `--min`.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
