Layout
justify-content
justify-content sets where items in a flexbox or grid sit along the main axis (the direction they run in) and how leftover space is shared.
Syntax
normal | <content-distribution>
| <overflow-position>? [ <content-position> | left | right ]Preview
1234
Presets
Sample
Drag the bottom-right corner to resize
Code
.box {
display: flex;
justify-content: space-between;
}Controls
justify-contentspace-between
safe / unsafeOnly matters when items overflow the box (they do not in this preview)
1234
About
Values
normal: the initial value. In a flexbox it is the same asflex-start.flex-start,flex-end: packs items toward the end where they start or end. Withflex-directionset torow-reverseand the like, the ends swap.center: packs items in the middle.space-between: puts the first and last items at the ends and shares the rest of the space equally between items.space-around: puts equal space on both sides of each item, so the space at the ends is half the space between items.space-evenly: makes every gap equal, including the ends.start,end: packs items toward the start or end given by the text direction. They do not swap with-reverse.left,right: packs items to the left or right. When items run vertically (column), they act asstart.stretch: the same asflex-startin a flexbox. In a grid it widensauto-sized columns to fill the box. To widen the items themselves in a flexbox, setflex-growon them.
The preview on this page sets display: flex as a helper declaration and places four 3em-wide items. In a grid, justify-content decides where the columns go as a group when they are narrower than the box.
safe and unsafe
Put safe before a position keyword and, when items overflow the box, they are packed to start instead, so the overflow never hides on the side you cannot scroll to (left or top). unsafe keeps the requested position even when items overflow. With neither, current browsers behave like unsafe. The items in this preview never overflow, so neither keyword changes what you see.