CSS justify-content Property Explained

What the CSS justify-content property does, with an example.

Published November 3, 2026

justify-content aligns flex or grid items along the main axis: flex-start, center, flex-end, space-between, space-around or space-evenly.

How it works

It distributes leftover space along the main axis (horizontal for rows). align-items handles the cross axis.

It only has an effect when there is free space.

Values and effects

justify-content: flex-start; → pack at start
justify-content: center; → centre items
justify-content: flex-end; → pack at end
justify-content: space-between; → edges touch, equal gaps
justify-content: space-around; → half-gaps at edges
justify-content: space-evenly; → equal gaps everywhere

Practical examples

Navbar

nav { display: flex; justify-content: space-between; }

Centre a button

.row { display: flex; justify-content: center; }

Even spacing

.tabs { display: flex; justify-content: space-evenly; }

Common mistakes

  • Expecting it to work without display: flex or grid.
  • Confusing it with align-items.
  • Using it when there is no free space.

Key takeaways

  • justify-content in one line: justify-content aligns flex or grid items along the main axis: flex-start, center, flex-end, space-between, space-around or space-evenly.
  • Inspect it live in DevTools → Styles.
  • Test across browsers and screen sizes.

FAQ

justify-content vs align-items?

justify-content is the main axis; align-items is the cross axis.

Is justify-content supported in all browsers?

Yes in all modern browsers; check caniuse.com for edge cases.

More CSS articles