HomeGuideLabGlossary

Align and distribute flex items in main direction with

has two kinds of values: alignment and distribution.

Alignment takes all flex items as a single chunk and moves them to a particular spot.

The default : flex-start takes flex items as a single chunk and places them at the start of the flex line.

123main-startmain directionflex-direction: rowjustify-content: flex-startINITIAL PROPERTY VALUE

Or, center takes the chunk and aligns its center to the center of the flex line.

main directionjustify-content: center123

Distribution takes the remaining space and distributes it around and between flex items.

Of course, this ends up moving the flex items into different spots, which is what we want.

112233justify-content: space-betweenI was hereNow I’ve moved here

If distribution can’t happen because there’s no space left, then fallback alignment happens.

Every distribution value like space-between or space-around has a fallback value.

justify-content: space-aroundjustify-content: centerFALLBACKjustify-content: space-aroundjustify-content: centerFALLBACK

This fallback value is the value that is used if the distribution value can’t do its job because there’s no space left.

12justify-content: space-evenlyI can’t work with this...Let’s use the fallback value instead

For example, space-between has a fallback of center.

12justify-content: space-evenlyjustify-content: centerI can’t work with this...?Why don’t you fall back on 21

Gaps are always inserted between flex items, no matter what

If you center-align your flex items, the gaps will be there between the flex items.

21

If you use : space-evenly, you might expect that there will be even spaces around and between flex items.

21justify-content: space-evenly

But because gaps are always inserted between flex items, the spaces between the flex items will be bigger than those around the flex items.

justify-content: space-evenly21This space ends up bigger