Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

CSS justify-content aligns or distributes content along a layout-specific axis: the main axis in Flexbox and the inline axis in Grid and multicol. It only has visible work to do when the layout leaves room to align or distribute; it does not affect an ordinary block container.

What does justify-content do?

justify-content controls how a layout container positions or distributes its content within the container’s content box. Its meaning depends on the layout mode. In Flexbox, it distributes available free space among items on a flex line. In Grid, it aligns the grid columns together within the grid container; it does not position one grid item inside its own cell. Multicol containers also use the property along the inline axis. See the MDN reference and the CSS Box Alignment Module Level 3 Working Draft.

The W3C draft describes the role of the property this way: “The content-distribution properties justify-content and align-content control alignment of the box’s content within its content box.” The draft is dated 30 January 2026 and is a Working Draft, not a final Recommendation.

Which axis does it affect?

Flexbox: the main axis

The main axis is set by flex-direction. With the default row, it runs along the flex container’s inline direction; with column, it runs vertically. So justify-content is not inherently a horizontal-centering property: its direction follows the flex layout.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Grid and multicol: the inline axis

In Grid, the property aligns the columns as a group along the inline axis. In multicol, it acts on the content along that same axis. If grid tracks already fill the available inline space, there may be no remaining room for a different distribution to show.

What do the common values do?

Value Effect Useful when
start / end Packs the content toward the logical start or end edge. You want alignment that follows the layout’s writing direction.
center Centers the content group in the alignment container. You want the group centered and have considered what happens if it overflows.
space-between Creates equal gaps between items, with no added gap at either outer edge. You want items such as navigation links to span the available space.
space-around Creates equal gaps between items and half-sized gaps at the edges. You want looser spacing with smaller outer gaps.
space-evenly Creates equal gaps between items and at both edges. You want the outer and inner spacing to match.
stretch Behavior depends on layout: it acts like flex-start in Flexbox; in Grid, auto-sized tracks can stretch. You are aligning Grid tracks and have checked their sizing behavior.

These distribution values need room to operate. The same keyword can have different practical effects in different layout modes, so check the container’s layout and sizing rather than assuming a value will create visible gaps.

How do you center items with Flexbox?

For a single flex line, set the container to Flexbox and use justify-content: center. This centers the items along the main axis. To center along the other axis, use the cross-axis alignment property, align-items.

.container {
  display: flex;
  justify-content: center;
  align-items: center;
}

Here, justify-content centers along the main axis and align-items aligns the items along the cross axis. If you change flex-direction, the main axis changes too.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Why is justify-content: center not working?

  1. Check the layout mode. The element must be a flex, grid, or multicol container. The property has no effect on an ordinary block container.
  2. Identify the relevant axis. In Flexbox it is the main axis, determined by flex-direction; in Grid and multicol it is the inline axis.
  3. Look for remaining space. In Flexbox, item sizing happens before distribution. If flex-grow has consumed the available free space, there is nothing left for justify-content to distribute.
  4. Check auto margins. Flex auto margins are resolved before justify-content; they may absorb the space you expected the property to distribute.
  5. In Grid, inspect the tracks. If the columns already occupy the available inline size, changing the group alignment may not visibly move them.
  6. Confirm what you intend to align. The property distributes or aligns content as a group. To position an individual item within its area, use an item-alignment property instead.

How is justify-content different from align-items?

In Flexbox, justify-content controls alignment along the main axis, while align-items controls item alignment along the cross axis. For the default row direction, that usually means justify-content affects horizontal distribution and align-items affects vertical alignment, subject to writing direction. In Grid, justify-content aligns the columns as a group; it is not the property for placing an individual grid item inside its grid area.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What other values and compatibility caveats matter?

MDN documents positional values including flex-start, flex-end, left, right, and normal, as well as distribution values and global CSS values. The W3C syntax also allows overflow-position keywords such as safe and unsafe before positional values. Safe alignment is specified to fall back toward the start when the requested alignment would cause overflow; unsafe alignment honors the requested position even when some content may become inaccessible.

Those overflow-position features and related scroll-safety behavior are marked at risk in the 30 January 2026 W3C Working Draft, so verify browser support before relying on them. MDN describes justify-content as widely available and reports availability across browsers since September 2015; that date is MDN’s compatibility summary, not a separate measurement.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.