Align content helps you control how multiple rows or columns of items are spaced inside a container. It makes your layout look neat and organized.
Align content in CSS
align-content: flex-start | flex-end | center | space-between | space-around | space-evenly | stretch;This property works only if the container has multiple lines (like with flex-wrap or grid).
It controls the space between rows or columns, not individual items.
align-content: flex-start;align-content: center;align-content: space-between;align-content: stretch;This example shows a flex container with wrapped boxes. The align-content: space-around; makes the rows have equal space above, below, and between them inside the container.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Align Content Example</title> <style> .container { display: flex; flex-wrap: wrap; height: 12rem; width: 12rem; border: 2px solid #333; align-content: space-around; background-color: #f0f0f0; } .box { flex: 0 0 4rem; height: 4rem; background-color: #4a90e2; margin: 0; color: white; display: flex; justify-content: center; align-items: center; font-weight: bold; border-radius: 0.25rem; } </style> </head> <body> <main> <section> <h1>Align Content: space-around</h1> <div class="container" aria-label="Container with boxes"> <div class="box">1</div> <div class="box">2</div> <div class="box">3</div> <div class="box">4</div> <div class="box">5</div> </div> </section> </main> </body> </html>
Align content only works when there are multiple lines (rows or columns) inside the container.
It does not affect single-line containers or individual item alignment.
Use with flex-wrap: wrap; or CSS Grid to see the effect.
Align content controls spacing between rows or columns inside a multi-line container.
It works only when items wrap to multiple lines.
Common values include flex-start, center, space-between, and stretch.