Learn CSS Visually - CSS explained one diagram at a time - flexbox, grid, the box model and more

justify-content vs align-items: What Is the Difference?

By · Updated

Disclosure: this page contains Amazon affiliate links. As an Amazon Associate we earn from qualifying purchases, at no extra cost to you.

Hi there, axis adventurer! justify-content vs align-items is the mix-up that sends more boxes flying in the wrong direction than any other in CSS, and the fix is one idea: one property works along the flow, the other works across it.

You set justify-content: center, nothing moved, so you tried align-items: center and the box went somewhere you didn’t expect.

Almost everyone has been there.

If you like a printed reference next to your editor, the CSS Visual Dictionary paperback on Amazon draws properties as pictures too, but the side-by-side diagram below settles this one for good.

Short answer: justify-content lines flex items up along the main axis (left to right in a default row) and shares out the free space there; align-items lines them up along the cross axis (top to bottom in a row). Switch to flex-direction: column and the two swap: justify-content moves items up and down, align-items left and right.

Side-by-side diagram of justify-content vs align-items in a CSS flexbox container: in a row, justify-content: center slides three boxes left and right along the main axis while align-items: center lines up three boxes of different heights top to bottom on the cross axis; in a column the arrows swap, so justify-content moves the stacked boxes up and down and align-items moves them left and right.
justify-content works along the flow of the items, align-items works across it — and flex-direction decides which way the flow runs.

What the diagram shows, in plain text:

What is the difference between justify-content and align-items?

The difference between justify-content and align-items is the axis: justify-content works along the main axis (the direction the flex items flow) and align-items works along the cross axis (at a right angle to it).

They also do different kinds of work, which is the part most tutorials skip: justify-content moves the items as a group by sharing out spare space, while align-items sets where each item sits inside its own line.

The rules come from the W3C CSS Box Alignment Module Level 3, the CSS Working Group specification that flexbox and CSS Grid share for alignment. It explains the naming like this:

This specification uses the terms “justify” and “align” to distinguish between alignment in the main/inline and cross/block dimensions, respectively. The choice is somewhat arbitrary, but having the two terms allows for a consistent naming scheme that works across all of CSS’s layout models

So “justify” = main axis, “align” = cross axis, in every layout mode. Here is the whole comparison in one table.

justify-content vs align-items in flexbox — compiled by Learn CSS Visually from the W3C CSS Box Alignment Module Level 3 (Working Draft, 8 October 2026), November 12, 2026
Questionjustify-contentalign-items
Which axis?main axiscross axis
Direction in a rowleft and rightup and down
Direction in a columnup and downleft and right
What it movesall the items as one group, by sharing out the free spaceeach item inside its own flex line
Set it onthe flex containerthe flex container
Default (initial value)normal, which acts as flex-start in flexboxnormal, which acts as stretch in flexbox
Needs free space to do anything?yes, on the main axisyes, the line must be taller (or wider) than the item
Override for one itemnone — use margin: auto on that itemalign-self on that item

Is justify-content horizontal and align-items vertical?

Only in a row. With the default flex-direction: row in a left-to-right language like English, justify-content is horizontal and align-items is vertical — which is why that shortcut sticks in people’s heads.

But the real rule is axes, not directions: justify-content follows the main axis and align-items follows the cross axis, wherever they point.

The writing direction counts too. In a right-to-left language such as Arabic or Hebrew (or any element with direction: rtl), a row’s main axis starts on the right, so justify-content: flex-start packs the items against the right edge.

Our flexbox explainer draws the main axis and cross axis on their own if you’d like a refresher.

What happens to justify-content and align-items in flex-direction: column?

In flex-direction: column the main axis turns to run top to bottom, so justify-content now moves items up and down and align-items now moves them left and right — the bottom half of the diagram.

Nothing about the properties changed; the axes turned underneath them. One catch: a column is usually only as tall as its content, so justify-content in a column has no free space to share until you give the container a height, such as min-height: 100vh.

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;  /* now top-to-bottom */
  align-items: center;             /* now left-to-right */
  min-height: 100vh;               /* gives justify-content room to work */
}

What does each justify-content value do?

Each justify-content value is a different way of sharing out the same free space along the main axis.

To make that concrete, we took one flex container 600px wide holding three items 100px wide with no gap — so 300px of free space — and worked out where each value puts the items. The picture is drawn to scale from those numbers.

To-scale chart of six CSS justify-content values in a 600px flex container with three 100px boxes: flex-start packs them on the left, flex-end on the right, center in the middle, space-between pushes the outer boxes to the edges, space-around leaves half-size gaps at the ends, and space-evenly leaves four equal 75px gaps; the free space in pixels is printed in each gap.
The same 300px of free space, shared out six ways. Blue numbers are the empty space in pixels.
justify-content item positions in a 600px flex container with three 100px items and no gap — calculated by Learn CSS Visually from the keyword rules in the W3C CSS Box Alignment Module Level 3 (Working Draft, 8 October 2026), November 12, 2026
ValueItems start atWhere the 300px of free space goes
flex-start (the default)0, 100, 200pxall 300px after the last item
flex-end300, 400, 500pxall 300px before the first item
center150, 250, 350px150px before, 150px after
space-between0, 250, 500pxtwo gaps of 150px between items, none at the edges
space-around50, 250, 450px50px at each edge, 100px between items
space-evenly75, 250, 425pxfour equal gaps of 75px, edges included

Add gap and the math only changes at the first step: with gap: 20px the two gaps take 40px, leaving 260px of free space for justify-content to share.

There are also start and end keywords from the Box Alignment module; they match flex-start and flex-end except in row-reverse and column-reverse, where flex-start follows the flipped flex direction and start follows the writing direction.

What is the difference between space-between, space-around and space-evenly?

The three space values differ only at the edges. space-between puts no space at the edges, space-around gives each item an equal slice of space on both sides (so the edges get half a gap), and space-evenly makes every gap the same, edges included.

The W3C spec words space-around as a half-size space on either end and space-evenly as a full-size space on either end.

They also behave differently with a single item.

The spec notes that space-between can only operate when there is more than one alignment subject, so one item under space-between sits at the start, while one item under space-around or space-evenly lands in the center (their fallback is safe center).

What does each align-items value do?

Each align-items value decides where every flex item sits across its line. Take a row 200px tall holding three items 40px, 80px and 60px tall; here is the top edge of each item for each value, from the same Box Alignment rules.

align-items positions in a 200px-tall flex row with items 40, 80 and 60px tall — calculated by Learn CSS Visually from the W3C CSS Box Alignment Module Level 3 (Working Draft, 8 October 2026), November 12, 2026
ValueTop edge of each itemWhat you see
flex-start0, 0, 0pxall hang from the top
flex-end160, 120, 140pxall sit on the bottom
center80, 60, 70pxall share one centre line, 100px down
stretch (the default)0, 0, 0pxitems with height: auto grow to 200px; items with a fixed height keep it and sit at the top
baselinedepends on the textthe first line of text in every item lines up

The center row is just (200 minus the item’s height) divided by 2: (200 — 40) / 2 = 80px, (200 — 80) / 2 = 60px and (200 — 60) / 2 = 70px.

Why are all my flex items the same height?

Flex items in a row are the same height because align-items defaults to normal, which behaves as stretch in a flex container.

The W3C spec says stretch only resizes a box whose height is auto, making it as close to filling the alignment container as possible while respecting min-height and max-height.

That’s great for equal-height cards. To let each item keep its natural height, set align-items: flex-start; and if stretch seems to do nothing, check for a fixed height on the items.

Why are justify-content or align-items not working?

When justify-content or align-items seems to do nothing, it’s almost always one of six things. Google’s web.dev Learn CSS course names the biggest one plainly: For the justify-content property to do anything you have to have spare space in your container on the main axis.

  1. No display: flex on the parent. Without it, the parent isn’t a flex container and neither property applies to its children.
  2. Set on the child instead of the parent. Both properties go on the flex container. Put on a flex item, justify-content doesn’t move that item at all — it would only arrange the item’s own children, and only if the item is a flex or grid container too.
  3. No free space on the main axis. Items with flex: 1, flex-grow or width: 100% already fill the row, so justify-content has nothing to share out.
  4. No free space on the cross axis. A row is only as tall as its tallest item, so align-items: center looks dead until the container has a height (or the items differ in height).
  5. The wrong axis for the direction. In flex-direction: column, centering left to right is align-items’ job, not justify-content‘s.
  6. A fixed size fighting stretch. align-items: stretch ignores items that have a set height (or width in a column).

Why doesn’t justify-items work in flexbox?

justify-items and justify-self are ignored in flexbox because the items on the main axis are handled as one group, not one by one.

Real talk: the justify is horizontal, align is vertical shortcut feels so right that I still catch myself reaching for it. It works right up until someone types flex-direction: column — then the whole thing flips and the shortcut quietly lies to you.

The W3C Box Alignment spec says of justify-self: This property does not apply to flex items, because there is more than one item in the main axis.

MDN Web Docs says the same from the reader’s side: We don’t have a justify-items or justify-self property available to us on the main axis as our items are treated as a group on that axis.

On the cross axis, by contrast, each item can be moved alone, which is why align-items and align-self both work in flexbox.

How do you move just one flex item?

To move one flex item on the cross axis, give it align-self; to move one on the main axis, give it an auto margin.

An auto margin soaks up all the free space on that side, so margin-left: auto pushes an item (and everything after it) to the far end of a row — the classic navbar with a logo on the left and links on the right.

.nav { display: flex; align-items: center; }
.nav .login { margin-left: auto; }   /* main axis: pushed to the right */
.nav .badge { align-self: flex-start; } /* cross axis: this one to the top */

What is the difference between align-items and align-content?

align-items places items inside each flex line; align-content places the lines themselves inside the container.

That means align-content only matters when the flex items wrap onto more than one line (flex-wrap: wrap) and the container is taller than those lines together; the W3C spec notes it only has an effect on multi-line flex containers.

So for a single row of buttons, reach for align-items; for a wrapping wall of tags, align-content: flex-start stops the rows from spreading out over the container’s height.

Do justify-content and align-items work the same in CSS Grid?

Partly. In CSS Grid, align-items works much as in flexbox — it places each item inside its grid area, here on the block (vertical) axis — but justify-content moves the whole set of grid tracks, and only when the tracks are narrower than the container.

Grid also gets the per-item property flexbox lacks: justify-items places each item inside its cell along the inline axis.

.grid {
  display: grid;
  grid-template-columns: repeat(3, 200px);  /* 600px of tracks... */
  width: 900px;                              /* ...in a 900px box */
  justify-content: center;  /* the 3 columns as a block, centered */
  justify-items: center;    /* each item centered inside its cell */
  align-items: center;      /* each item centered top to bottom */
}

place-items: center is the grid shorthand for align-items: center plus justify-items: center — the shortest way to center one thing inside a grid cell.

What happens when flex items are too big to fit?

When flex items are bigger than their container, the free space is negative, and justify-content: center pushes them past both edges equally — so the start can end up cut off where you can’t scroll to it.

Three items 250px wide with flex-shrink: 0 in a 600px container overflow by 150px, which center splits into 75px hanging off the left and 75px off the right.

Write safe center to stop that: the W3C spec says that if the items overflow, safe aligns them as if the alignment mode were flex-start.

.toolbar {
  display: flex;
  justify-content: safe center;  /* center if it fits, start if not */
  overflow-x: auto;
}

How do you center a div with justify-content and align-items?

To center a div both ways, make its parent a flex container and set both properties to center: justify-content handles the main axis, align-items the cross axis, so between them both directions are covered.

Give the parent a height, or there’s no vertical room to center in. Our guide to centering a div draws five more ways, including grid, margin: auto and absolute positioning.

.parent {
  display: flex;
  justify-content: center;  /* horizontally, in a row */
  align-items: center;      /* vertically, in a row */
  min-height: 100vh;
}

Do justify-content and align-items work in every browser?

Yes. flex-start, flex-end, center, space-between and space-around came with flexbox itself, and according to MDN’s browser compatibility data, read on November 12, 2026, unprefixed justify-content and align-items work since Chrome 29, Edge 12, Firefox 20 and Safari 9.

The newer keywords came later:

space-evenly
Chrome 60, Edge 79, Firefox 52, Safari 11
start and end in flexbox
Chrome and Edge 93, Firefox 45, Safari 15.4
safe and unsafe
Chrome and Edge 115, Firefox 63, Safari 17.6

If you still support very old Safari, flex-start, flex-end and center are the safest picks; everything in this tutorial works in current browsers.

Grab three boxes, give the parent display: flex and a height, and click through every justify-content and align-items value in the DevTools flexbox editor. Then flip it to a column and do it again. Five minutes of that and your boxes will finally go where you point them.

Sources and further reading

Questions and answers

Is justify-content horizontal or vertical?

justify-content is horizontal only in a default flex row (flex-direction: row) in a left-to-right language. It always works along the main axis, so in flex-direction: column it becomes vertical and moves items up and down.

Why is align-items center not working?

Usually the flex container has no extra height: a row is only as tall as its tallest item, so there is no room to center in. Give the container a height or min-height, check that display: flex is on the parent (not the child), and remember that in a column align-items centers left to right.

What is the difference between align-items and align-content?

align-items positions the items inside each flex line, while align-content positions the lines themselves inside the container. align-content only has an effect when items wrap onto more than one line with flex-wrap: wrap.

Why does justify-items not work in flexbox?

In flexbox the items on the main axis are treated as one group, so justify-items and justify-self are ignored there. Use justify-content to move the group, or an auto margin such as margin-left: auto to push one item. justify-items does work in CSS Grid.

What is the difference between space-between and space-evenly?

space-between puts all the free space between the items and none at the edges, so the first and last items touch the container. space-evenly makes every gap equal, including the gaps at both edges. In a 600px container with three 100px items, space-between gives two 150px gaps and space-evenly four 75px gaps.

How this was written: Written from the W3C CSS Box Alignment Module Level 3 (Working Draft, 8 October 2026), MDN Web Docs and MDN’s browser compatibility data, Google’s web.dev Learn CSS course and the Chrome DevTools documentation, all read on November 12, 2026. The item positions in both tables are our own arithmetic from the spec’s keyword rules. Code samples are simplified for learning; check MDN before shipping newer keywords.

Oh, one more thing…

If this helped, you’ll like our free updates: the insights we discover while researching, and the moments worth sharing with other people learning CSS — no spam, no promotions.

One short email when there’s something worth your time. Unsubscribe any time.