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
Start learning this pattern below
Jump into concepts and practice - no test required
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.
Practice
align-content control in a flex container?Solution
Step 1: Understand the role of
This property controls how multiple rows or columns are spaced inside a container when items wrap to more than one line.align-contentStep 2: Differentiate from other properties
align-itemsaligns individual items on a single line, not spacing between lines. Font size and background color are unrelated.Final Answer:
The spacing between rows or columns when items wrap to multiple lines -> Option DQuick Check:
Align-content = spacing between wrapped lines [OK]
- Confusing align-content with align-items
- Thinking it changes font or colors
- Using it when items do not wrap
Solution
Step 1: Identify the property for multi-line alignment
align-contentcenters the space between multiple lines in a flex container.Step 2: Differentiate from other alignment properties
align-itemscenters items on a single line,justify-contentaligns along the main axis, andtext-alignaffects inline text alignment.Final Answer:
align-content: center; -> Option AQuick Check:
Center multi-line content with align-content: center [OK]
- Using align-items instead of align-content
- Confusing justify-content with align-content
- Applying text-align to flex containers
display: flex; flex-wrap: wrap; align-content: space-between; height: 200px;
What will
align-content: space-between; do visually?Solution
Step 1: Understand
This value distributes rows so the first row is at the top, the last row at the bottom, and equal space between rows.space-betweenbehaviorStep 2: Visualize the effect in a 200px tall container
Rows spread out vertically with no extra space above the first or below the last row.Final Answer:
Place the rows evenly with space between them, top and bottom edges have no extra space -> Option BQuick Check:
space-between = equal gaps between rows, edges flush [OK]
- Thinking space-between adds space at container edges
- Confusing with space-around or space-evenly
- Expecting rows to stretch to fill height
align-content property has no visible effect:display: flex; flex-wrap: nowrap; align-content: center; height: 150px;
What is the main reason
align-content does not work here?Solution
Step 1: Check the
It is set toflex-wrapvaluenowrap, so all items stay on a single line.Step 2: Understand when
align-contentworksalign-contentonly affects spacing between multiple lines, so it has no effect if items do not wrap.Final Answer:
flex-wrapis set tonowrap, so items do not wrap to multiple lines -> Option CQuick Check:
Align-content needs wrapped lines to work [OK]
- Assuming align-content works without wrapping
- Thinking align-content applies to grid only
- Ignoring flex-wrap setting
Solution
Step 1: Identify the need for multi-line stretching
To stretch rows evenly,align-content: stretch;is required and items must wrap.Step 2: Confirm correct flex-wrap and height
flex-wrap: wrap;allows multiple lines, and setting a container height (300px) lets stretching be visible.Step 3: Exclude incorrect options
flex-wrap: nowrap;prevents wrapping,align-itemsaffects single line items, andjustify-contentcontrols main axis, not cross axis.Final Answer:
display: flex; flex-wrap: wrap; align-content: stretch; height: 300px; -> Option AQuick Check:
Stretch multi-line rows with align-content: stretch and wrap [OK]
- Using nowrap disables multi-line stretching
- Confusing align-items with align-content
- Using justify-content instead of align-content
