justify-content (FlexBox property)

The justify-content property aligns flex items along the main axis (horizontal in default flex-direction: row). It distributes extra space when items do not fully occupy the container.

img


Available Values

ValueDescription
flex-startItems packed toward the start of the main axis (left in LTR).
flex-endItems packed toward the end of the main axis (right in LTR).
centerItems centered along the main axis.
space-betweenItems evenly distributed; first item at start, last at end, equal space between.
space-aroundItems evenly distributed with equal space around each item (half-size space at ends).
space-evenlyItems distributed with equal space between all items, including ends.

Code Example

img

GT-Sandbox-Snapshot

Command to reproduce:

gt.sandbox.checkout.commit a57600e8b590e7527511 \
&& cd "${GT_SANDBOX_REPO}" \
&& cmd.run.announce "chrome ./main/index.html"

Recorded output of command:

       _chrome ./main/index.html
Opening in chrome: ./main/index.html

Use Cases

  • Navigation Bars: Align links to the left, center, or right.
  • Toolbars: Distribute buttons evenly or group them at edges.
  • Card Layouts: Control spacing between cards in a row.

Tip: For vertical alignment (cross-axis), use align-items or align-content instead.


Backlinks