Usage of CSS align-content property center value

The CSS align-content property with the center value is used to center flex lines in a flex container. This property only works when the flex container has multiple lines created by flex-wrap: wrap.

Syntax

.container {
    display: flex;
    flex-wrap: wrap;
    align-content: center;
}

Example

The following example demonstrates how to center flex lines within a flex container −

<!DOCTYPE html>
<html>
<head>
<style>
    .mycontainer {
        display: flex;
        height: 300px;
        width: 400px;
        background-color: lightcoral;
        align-content: center;
        flex-wrap: wrap;
        border: 2px solid #333;
    }
    .mycontainer > div {
        background-color: yellow;
        text-align: center;
        line-height: 60px;
        font-size: 20px;
        width: 100px;
        height: 60px;
        margin: 5px;
        border: 1px solid #000;
    }
</style>
</head>
<body>
    <h3>Flex Lines Centered</h3>
    <div class="mycontainer">
        <div>Item 1</div>
        <div>Item 2</div>
        <div>Item 3</div>
        <div>Item 4</div>
        <div>Item 5</div>
        <div>Item 6</div>
    </div>
</body>
</html>
A red flex container with yellow flex items arranged in multiple rows, with all the flex lines centered vertically within the container's height.

Key Points

  • The align-content: center property centers the flex lines as a group within the container
  • It requires flex-wrap: wrap to create multiple lines
  • This property affects the distribution of space between and around flex lines

Conclusion

The align-content: center property is essential for centering wrapped flex lines vertically within their container. It provides precise control over multi-line flex layouts and ensures balanced spacing.

Updated on: 2026-03-15T13:05:59+05:30

183 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements