CSS justify-content Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The justify-content property distributes free space between and around content along the main axis of a flex container, and along the inline axis of a grid or multicol container.

In a row flex, that means left–right packing: center, space-between, and friends. There must be leftover free space, or every keyword looks the same. It does not apply to normal block boxes. To align items on the cross axis, use align-items. To pack wrapped lines, use align-content.

Standard-track.

Not deprecated and not experimental. Flex and grid values are widely available (Baseline since 2015). Keywords like safe / unsafe and some newer positions have thinner support.

CSS Syntax

syntax.css
justify-content: normal | flex-start | flex-end | center | space-between | space-around | space-evenly | stretch | initial | inherit;

Also valid: start, end, left, right, and optional safe / unsafe before a position keyword.

Property Values

ValueDescriptionTry it
normalDefault. In flex, packs like startTry it
flex-startPack items toward the main-start edgeTry it
flex-endPack items toward the main-end edgeTry it
centerPack items together in the middle of the main axisTry it
space-betweenFirst at start, last at end, equal gaps betweenTry it
space-aroundEqual gaps between items; half a gap at each edgeTry it
space-evenlyEqual gaps between items and at both edgesTry it
stretchIn flex, acts like start. In grid, can stretch auto tracksTry it
initialResets to normalTry it
inheritTakes the parent’s justify-content (not inherited by default)Try it

How to Use justify-content

Make a flex or grid container wider than its items (or tracks), then choose how free space is shared.

  1. Set display: flex or display: grid on the container.
  2. Leave free space on the main / inline axis (a wider box, or fixed-size items that do not grow).
  3. Keep flex-grow at 0 on study examples so free space remains for distribution.
  4. Set justify-content on the container. It is not inherited.
PieceRequired?Role
Flex or grid containerYesThe box whose free space you distribute
Free space on main / inline axisYesWithout leftover space, every keyword looks the same
Fixed-size items (or tracks)RecommendedSo growth does not eat the free space
KeywordYescenter, space-between, space-evenly, and the others above

Live Preview

Three fixed-width flex items in a wider row. Change justify-content and watch the free space move.

Gray areas are free space on the main axis.

Row
One
Two
Three

justify-content: center

CSS Examples

Each snippet keeps only what justify-content needs: a container, free space, and fixed-size children. Use Try It Yourself for a live editor.

Example 1 — Center Items

Pack three flex items together in the middle of a wider row.

CSS
<style>
  section {
    display: flex;
    justify-content: center;
    border: 1px solid #ccc;
  }
  div {
    width: 60px;
  }
</style>

<section>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
</section>
Try It Yourself

How It Works

  1. Make a row flex. display: flex lays children out on the main axis (left to right by default).
  2. Keep item width fixed. width: 60px stops items from growing into the free space.
  3. Leave free space. The section is wider than the three boxes, so spare space exists on the sides.
  4. Center the group. justify-content: center packs the items together and places that group in the middle.

Example 2 — Space Between

Pin the first item to the start and the last item to the end.

CSS
<style>
  section {
    display: flex;
    justify-content: space-between;
    border: 1px solid #ccc;
  }
  div {
    width: 60px;
  }
</style>

<section>
  <div>One</div>
  <div>Two</div>
  <div>Three</div>
</section>
Try It Yourself

How It Works

  1. Same three items. Fixed widths leave free space in a full-width flex row.
  2. Pin the edges. space-between puts the first item on the start edge and the last on the end edge.
  3. Equal inner gaps. Spare space is split evenly between the pairs of neighbors.
  4. Compare. space-evenly also adds equal space before the first and after the last item.

Example 3 — Grid Columns

Distribute fixed-width columns inside a wider grid with equal outer and inner gaps.

CSS
<style>
  section {
    display: grid;
    grid-template-columns: 60px 60px 60px;
    justify-content: space-evenly;
    border: 1px solid #ccc;
  }
</style>

<section>
  <div>A</div>
  <div>B</div>
  <div>C</div>
</section>
Try It Yourself

How It Works

  1. Fixed tracks. Three 60px columns are narrower than the section, so free inline space exists.
  2. Justify the tracks. justify-content moves the columns as a group—not the content inside each cell.
  3. Even gaps. space-evenly makes the space before the first column, between columns, and after the last column the same size.
  4. Cell alignment. To align content inside a cell, use justify-items instead.

Edge Cases & Pitfalls

If nothing moves, free space is usually already gone.

grow

flex-grow eats free space

If any item on the line has flex-grow greater than 0, that growth uses the free space first. Then justify-content has nothing left to distribute.

space

No free space, no visible change

If the container is only as wide as its items, every keyword looks the same. Give the container a larger main size, or shrink the items.

axis

Column flex flips the axis

With flex-direction: column, the main axis is vertical. justify-content then packs top to bottom and needs spare height.

vs

Not align-items or justify-items

align-items is cross-axis. justify-items aligns content inside grid cells. justify-content distributes free space around items or tracks.

stretch

stretch in flex is a no-op lookalike

In flexbox, main-axis stretch is controlled by flex / flex-grow, so justify-content: stretch behaves like start. Stretching tracks is a grid concern.

safe

safe / unsafe are optional

safe center falls back toward start if centering would clip overflow. Support is thinner than the basic keywords—prefer plain center unless you need overflow safety.

Browser Support

justify-content is a browser layout property for flex, grid, and multicol. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available since 2015

justify-content

Flex: Chrome 29+, Firefox 28+, Safari 9+, Edge 12+. Grid: Chrome 57+, Firefox 52+, Safari 10.1+, Edge 16+. Internet Explorer 11 is flex-only (older values).

96% Flex and grid support
Google Chrome 29+ flex · 57+ grid
Full support
Mozilla Firefox 28+ flex · 52+ grid
Full support
Apple Safari 9+ flex · 10.1+ grid
Full support
Microsoft Edge 12+ flex · 16+ grid
Full support
Opera 16+ flex · grid in Chromium 57+
Full support
Samsung Internet 4+ flex · 6.2+ grid
Full support
Internet Explorer 11 · Old flex only
Partial
justify-content Widely supported

Bottom line: Safe for flex and grid in current browsers. Prefer start/end/center and the space-* keywords for widest reach. safe/unsafe and some logical keywords vary by browser.

Key Takeaways

  • Role: distribute free space along the flex main axis or grid inline axis.
  • Needs free space: fixed items (or tracks) inside a larger container; avoid flex-grow eating the gap.
  • Not align-items: that property is cross-axis; this one is main / inline.
  • Initial value: normal. It is not inherited.

One line: justify-content shares leftover main-axis (or grid inline) space—after sizes are set, and only if free space remains.

Frequently Asked Questions

It distributes free space between and around items along the main axis of a flex container, or along the inline axis of a grid (or multicol) container.
The initial value is normal. In a flex container that behaves like start (pack toward the main-start edge).
justify-content works along the main axis (or grid inline axis) and needs free space. align-items aligns items on the cross axis inside a line or area.
There must be leftover free space. If items grow with flex-grow, or the container is only as wide as its content, every keyword looks the same.
Yes. It justifies the grid tracks (columns on a horizontal grid) when the grid is narrower than its container. It does not align items inside cells—that is justify-items.
Flex support goes back to Chrome 29, Firefox 28, Safari 9, and Edge 12. Grid support starts at Chrome 57, Firefox 52, and Safari 10.1. It is a browser layout property, not a Node.js feature.

Next: justify-items

Align content inside grid cells along the inline axis.

justify-items tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful