# Perfect Centering

> Center anything horizontally and vertically with two lines of CSS Grid.

- Category: [CSS Layouts](https://copy-css.com/category/layouts)
- Tags: center, grid, place-items, align, vertical
- Live preview: https://copy-css.com/snippets/perfect-center
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<div class="center">
  <div>Centered</div>
</div>
```

## CSS

```css
/* Centers its children horizontally and vertically */
.center {
  display: grid;
  place-items: center;
}
```

## Notes

- This CSS Perfect Centering is 5 lines of pure CSS (0.1 KB) with no JavaScript and no dependencies. It uses CSS Grid.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
