🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Align-Content

Control the spacing of lines in your flex layouts. Master the art of wrapping and alignment.

style.css
.container {
display: flex;
flex-wrap: wrap;
align-content: center;
}
style.css
1 / 8
📐

Tutor:The 'align-content' property aligns a flex container's lines within the flex container when there is extra space in the cross-axis.


CSS Layout Mastery

Unlock nodes by mastering alignment properties.

Concept 1: Flex Containers

Before aligning content, you must establish a flex context using display: flex. By default, this puts items in a single row.

System Check

What is the default behavior of flex items?


Community Layouts

Share Your Grids

Created a cool layout using `align-content`? Share your snippet.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Align-Content Property

Author

Pascual Vila

Frontend Instructor.

The align-content property modifies the behavior of the flexible container wrapping. It determines how lines are spaced within the container along the cross-axis.

The Prerequisite: Wrapping

This is the most common pitfall: align-content has no effect on a single-line flex container. For this property to work, your container must have:

  • display: flex (or grid)
  • flex-wrap: wrap
  • A height (or min-height) greater than the content needs, creating extra space to distribute.

Common Values

  • flex-start: Packs lines to the start of the cross-axis.
  • flex-end: Packs lines to the end.
  • center: Packs lines in the middle.
  • space-between: Distributes lines; first line at start, last at end.
  • space-around: Distributes lines with equal space around them.
  • stretch: (Default) Lines stretch to take up the remaining space.

align-items vs align-content

Use align-items when: You want to align items within a single line (or for every line individually relative to that line's height).

Use align-content when: You have multiple lines and want to control the spacing *between* or *around* those lines within the container.

Flexbox Alignment Glossary

align-content
Aligns a flex container's lines within the flex container when there is extra space in the cross-axis. Requires wrapping.
Cross-Axis
The axis perpendicular to the main axis. If flex-direction is row, the cross-axis is vertical. align-content works on this axis.
flex-wrap
By default, flex items will all try to fit onto one line. You can change that and allow the items to wrap as needed with this property.