align-content
Positions entire lines of items along a container’s cross axis.
- Initial value
normal- Inherited
- No
- Animatable
- no
- Applies to
- flex containers with multiple lines, grid containers, multi-column and block containers
- JavaScript
element.style.alignContent = "center"
Example
#.badges {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
gap: 6px;
height: 120px;
}<div class="badges stage">
<span class="box">7-day streak</span><span class="box">100 tasks</span><span class="box">CSS master</span><span class="box">First page</span>
</div>Definition and usage
#The align-content property works at the level of lines, not individual items. In a flex container it only matters once items wrap onto several lines (flex-wrap: wrap) and there’s free space left on the cross axis.
The values resemble justify-content: lines can bunch up at the start, in the center, at the end, or spread out with equal spacing. By default, lines stretch to fill the container.
In a Grid layout, the same property positions entire rows, and in newer browsers it also works on plain block containers, which lets you center content vertically without Flexbox.
Syntax
#align-content: normal | flex-start | flex-end | center | space-between | space-around | space-evenly | stretch;Values
#- Lines bunch up at the top edge.
- Lines group together in the center.
- Lines line up at the bottom.
- The first line at the top, the last at the bottom, the rest of the space between them.
- Lines stretch to fill the height.
Values in practice
#flex-start
.demo { align-content: flex-start; }center
.demo { align-content: center; }flex-end
.demo { align-content: flex-end; }space-between
.demo { align-content: space-between; }stretch
.demo { align-content: stretch; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- If
align-contentdoesn’t change anything, check that the container hasflex-wrap: wrapand a height greater than its content. align-items, notalign-content, is what aligns items within a single line.
Related entries
#- align-itemsAligns items along the cross axis of a flex or grid container.
- flex-wrapLets flex items wrap onto new lines when there isn’t enough room.
- justify-contentPositions items along the main axis of a flex or grid container.
- place-contentA shorthand that sets align-content and justify-content at the same time.
Spotted a mistake or missing an example? Write to us.