Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The justify-content property

Reference for the CSS justify-content property: flex-start, center, space-between, space-around, space-evenly and more, with live flexbox examples.

The justify-content property distributes the free space on the main axis of a flex container. In a row, that means horizontal alignment (in left-to-right text); in a column, vertical. It only has an effect when the items do not already fill the line: when they do, there is no free space to distribute.

The same property also aligns the columns of a grid inside its container, and it works on block containers in current browsers, but flexbox is where you will use it most.

CSS
.toolbar { display: flex; justify-content: space-between; }

Try it

Every distribution
Column direction and a centered pair

Syntax

CSS
justify-content: normal
  | <content-distribution>
  | <overflow-position>? [ <content-position> | left | right ];

/* <content-distribution>: space-between | space-around | space-evenly | stretch */
/* <content-position>: center | start | end | flex-start | flex-end */
/* <overflow-position>: safe | unsafe */
  • Initial value: normal (behaves like flex-start in a flex container and like stretch in a grid)
  • Applies to: flex containers, grid containers and multi-column containers; current browsers also support block containers
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
flex-start Items packed at the start of the main axis (flexbox only).
flex-end Items packed at the end of the main axis (flexbox only).
start, end Like flex-start/flex-end, but based on the writing mode and also valid in grid.
center Items packed in the middle.
left, right Packed to the physical left or right edge, whatever the direction.
space-between First item at the start, last item at the end, equal space between items.
space-around Equal space around each item, so the space at the edges is half the space between items.
space-evenly The same space between items and at both edges.
stretch In grid, auto-sized tracks grow to fill the container. It does not stretch flex items; use flex-grow for that.
safe / unsafe Optional prefix. safe center falls back to start instead of overflowing off the start edge when the content is too big.

Usage notes

  • It follows the main axis. After flex-direction: column, it works vertically. For the cross axis use align-items.
  • Space distribution needs free space. If the items already fill or overflow the line, space-between and friends have nothing to distribute, and center can overflow on both sides.
  • Auto margins win. An item with margin-left: auto takes the free space first, so justify-content has no effect on that line. This is the classic way to push one item to the far end.
  • space-between with one item puts it at the start. space-around and space-evenly center it.
  • Wrapped lines are each aligned on their own.
  • Gaps stay. gap remains as the minimum space between items before the distribution adds more.
  • Centering both ways is justify-content: center; align-items: center;, also written with place-content or place-items.

Browser support

Supported in every browser for flexbox and grid. Using it on plain block containers works in current browsers but not in older ones.