# Grid alignment

> Align all grid items from their container, or position one item inside its cell.

Utility classes for CSS grid container and item alignment.

Source: https://docs.tabler.io/ui/utilities/grid-alignment

---

Use `.justify-items-*` or `.place-items-*` on an element with `.d-grid` to align all items inside their cells. Choose from `start`, `end`, `center`, `baseline`, and `stretch` (the default).

## Justify items

`.justify-items-*` aligns the items along the inline (horizontal) axis of each cell.

```html
<div class="d-grid justify-items-center gap-2 p-2 border rounded" style="grid-template-columns: repeat(3, 1fr)">
  <div class="p-2 bg-primary-lt rounded">One</div>
  <div class="p-2 bg-primary-lt rounded">Two</div>
  <div class="p-2 bg-primary-lt rounded">Three</div>
</div>
```

## Justify self

Use `.justify-self-start`, `.justify-self-end`, or `.justify-self-center` on a grid item to override the container's alignment.

```html
<div class="d-grid grid-cols-3 justify-items-center gap-2 p-2 border rounded">
  <div class="justify-self-start p-2 bg-primary-lt rounded">Start</div>
  <div class="justify-self-center p-2 bg-primary-lt rounded">Center</div>
  <div class="justify-self-end p-2 bg-primary-lt rounded">End</div>
</div>
```

## Place items

`.place-items-*` sets `align-items` and `justify-items` together, so `.place-items-center` centers each item on both axes.

```html
<div class="d-grid place-items-center gap-2 p-2 border rounded" style="grid-template-columns: repeat(3, 1fr); grid-auto-rows: 6rem">
  <div class="p-2 bg-primary-lt rounded">One</div>
  <div class="p-2 bg-primary-lt rounded">Two</div>
  <div class="p-2 bg-primary-lt rounded">Three</div>
</div>
```

## Responsive

All classes have responsive variants, for example `.justify-items-md-start`, `.justify-self-md-center`, or `.place-items-lg-center`.

```html
<div class="d-grid place-items-center place-items-md-start">...</div>
```

Apply the responsive class to the item when using `justify-self`. This item starts at the beginning of its cell and centers from the `md` breakpoint.

```html
<div class="d-grid grid-cols-1 gap-2 p-2 border rounded">
  <div class="justify-self-start justify-self-md-center p-2 bg-primary-lt rounded">Start, then center from md</div>
</div>
```

## Accessibility

- Alignment moves items visually, not in the reading order. Screen readers and keyboard focus still follow the order in the markup.
- `justify-items` has no effect on a flex container. Use `justify-content` there instead.
