# Centered Last Row Grid

> A wrapping grid of equal cards where an uneven last row is centered instead of hugging the left.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: flex-wrap, orphans, centered, responsive grid, logos, team
- Live preview: https://copy-css.com/snippets/centered-last-row
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

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

## CSS

```css
/* Flexbox, not Grid: only flex can center a short last row */
.grid-center {
  --cols: 3;
  --min: 180px;
  --gap: 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--gap);
}

.grid-center > * {
  flex: 0 1 calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols));
  min-width: min(100%, var(--min));
}
```

## Notes

- This CSS Centered Last Row Grid is 15 lines of pure CSS (0.3 KB) with no JavaScript and no dependencies. It uses Flexbox and custom properties.
- Customize with: `--cols`, `--min`, `--gap`.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
