---
title: "align-content: The Simplest Way to Center Content with CSS"
description: "Finally, we can center things in block layouts without flexbox gymnastics"
canonical: "https://www.trevorlasn.com/blog/css-align-content-in-block-layouts"
author: "Trevor I. Lasn"
published: "2024-12-13"
last-updated: "2024-12-13"
topics: ["CSS"]
---

# align-content: The Simplest Way to Center Content with CSS

Finally, we can center things in block layouts without flexbox gymnastics

By Trevor I. Lasn · Published 2024-12-13 · https://www.trevorlasn.com/blog/css-align-content-in-block-layouts

Block layouts have been part of CSS since the beginning, but they've always lacked proper alignment controls. Now, with `align-content` support in block layouts, we can distribute content vertically with the same flexibility we've enjoyed in flex and grid.

[Browser support for `align-content-block` on webstatus.dev](https://webstatus.dev/features/align-content-block)

The old approaches required either flexbox or grid as a workaround. With flex, we needed multiple properties to achieve vertical centering. Grid made it a bit simpler with `align-content`, but still required changing the layout mode.

With the new `align-content` support in block layouts, we can achieve the same result while maintaining block layout semantics. No need to switch layout modes - just add `align-content` to your block container.

```css title="CSS" del={1-13} ins={13-19}
/* Old approach with flex */
.container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
/* Old approach with grid */
.container {
  min-height: 100vh;
  display: grid;
  align-content: center;
}
/* New approach with align-content */
.container {
  min-block-size: 100vh;
  display: block;
  align-content: center;
}
```

The browser will distribute the available space automatically, positioning your content in the center of the container. This works with any block container that has a defined block size.

<br />

### Browser Support and Fallbacks

This feature requires browsers that support the latest [CSS Box Alignment specification.](https://www.w3.org/TR/css-box-4/) For older browsers, you can use either the flex or grid approach as a fallback. 

```css title="CSS"
@supports (display: block) and (align-content: center) {
  .container {
    display: block;
    align-content: center;
  }
}

/* Fallback for older browsers */
.container {
  min-height: 100vh;
  display: grid;
  align-content: center;
}
```

The safest approach is to use [@supports](https://www.trevorlasn.com/blog/detect-css-features-with-supports-property) to provide a fallback for browsers that don’t support `align-content` in block layouts. This way, you can ensure a consistent experience across all browsers.
