The justify-content property

justify-content is set on a flex or grid container and distributes free space between its items along the main axis: it packs them at the start or end, centers them or spreads them out evenly.

Syntax

justify-content: flex-start | center | flex-end | space-between | space-around | space-evenly | normal;
Initial value
normal
Inherited
no
Applies to
flex, grid and multi-column containers

Values

ValueWhat it does
normalthe initial value; in a flex container it behaves as flex-start
flex-startitems at the start of the main axis
centeritems in the center
flex-enditems at the end of the main axis
space-betweenfirst and last items at the edges, the rest of the space shared equally between items
space-aroundequal space around each item (half as much at the edges as between items)
space-evenlyequal gaps everywhere, edges included

Example

.row {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: #f1f5f9;
}
.row span {
  padding: 6px 12px;
  background: #0284c7;
  color: #fff;
  border-radius: 4px;
}
.start { justify-content: flex-start; }
.center { justify-content: center; }
.between { justify-content: space-between; }
.evenly { justify-content: space-evenly; }
<p>flex-start</p><div class="row start"><span>1</span><span>2</span><span>3</span></div>
<p>center</p><div class="row center"><span>1</span><span>2</span><span>3</span></div>
<p>space-between</p><div class="row between"><span>1</span><span>2</span><span>3</span></div>
<p>space-evenly</p><div class="row evenly"><span>1</span><span>2</span><span>3</span></div>

Result

▶ Open in HTML Editor

Good to know

  • It works along the main axis: with flex-direction: column the alignment becomes vertical.
  • It needs free space. If items stretch (flex: 1 or flex-grow), there is nothing to distribute and the values look the same.
  • To push just one item away (for example, a button to the end of a menu), margin-left: auto on that item is simpler.
  • Alignment along the cross axis is set by another property, align-items.

Sources and specification

See also