justify-content vs align-items: What Is the Difference?
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.
What the diagram shows, in plain text:
- Top left,
flex-direction: row+justify-content: center: three boxes sit side by side in the middle of the row. The arrow runs left and right: in a row, the main axis is horizontal. - Top right,
flex-direction: row+align-items: center: three boxes of different heights (40, 80 and 60px tall) share one centre line. The arrow runs up and down: in a row, the cross axis is vertical. - Bottom left,
flex-direction: column+justify-content: center: the boxes are stacked and centered top to bottom. The same property now moves things up and down. - Bottom right,
flex-direction: column+align-items: center: stacked boxes of different widths are centered left to right. The same property now moves things sideways.
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.
| Question | justify-content | align-items |
|---|---|---|
| Which axis? | main axis | cross axis |
| Direction in a row | left and right | up and down |
| Direction in a column | up and down | left and right |
| What it moves | all the items as one group, by sharing out the free space | each item inside its own flex line |
| Set it on | the flex container | the flex container |
| Default (initial value) | normal, which acts as flex-start in flexbox | normal, which acts as stretch in flexbox |
| Needs free space to do anything? | yes, on the main axis | yes, the line must be taller (or wider) than the item |
| Override for one item | none — use margin: auto on that item | align-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.
| Value | Items start at | Where the 300px of free space goes |
|---|---|---|
flex-start (the default) | 0, 100, 200px | all 300px after the last item |
flex-end | 300, 400, 500px | all 300px before the first item |
center | 150, 250, 350px | 150px before, 150px after |
space-between | 0, 250, 500px | two gaps of 150px between items, none at the edges |
space-around | 50, 250, 450px | 50px at each edge, 100px between items |
space-evenly | 75, 250, 425px | four 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.
| Value | Top edge of each item | What you see |
|---|---|---|
flex-start | 0, 0, 0px | all hang from the top |
flex-end | 160, 120, 140px | all sit on the bottom |
center | 80, 60, 70px | all share one centre line, 100px down |
stretch (the default) | 0, 0, 0px | items with height: auto grow to 200px; items with a fixed height keep it and sit at the top |
baseline | depends on the text | the 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.
- No
display: flexon the parent. Without it, the parent isn’t a flex container and neither property applies to its children. - Set on the child instead of the parent. Both properties go on the flex container. Put on a flex item,
justify-contentdoesn’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. - No free space on the main axis. Items with
flex: 1,flex-groworwidth: 100%already fill the row, sojustify-contenthas nothing to share out. - No free space on the cross axis. A row is only as tall as its tallest item, so
align-items: centerlooks dead until the container has a height (or the items differ in height). - The wrong axis for the direction. In
flex-direction: column, centering left to right isalign-items’ job, notjustify-content‘s. - A fixed size fighting
stretch.align-items: stretchignores items that have a setheight(orwidthin 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
startandendin flexbox- Chrome and Edge 93, Firefox 45, Safari 15.4
safeandunsafe- 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
- W3C: CSS Box Alignment Module Level 3 — the specification (Working Draft, 8 October 2026): justify-content, align-items, align-self, the space-* keywords, stretch, safe and fallback alignment
- W3C: CSS Flexible Box Layout Module Level 1 — the main axis, cross axis and flex lines
- MDN Web Docs: Aligning items in a flex container — why flexbox has no justify-items, and auto margins
- MDN Web Docs: justify-content — every value with live examples
- MDN Web Docs: align-items — every value with live examples
- MDN browser-compat-data — version numbers for justify-content, align-items, space-evenly, start/end and safe, read November 12, 2026
- web.dev Learn CSS: Flexbox — Google’s free CSS course: alignment and spare space
- Chrome DevTools: inspect and debug CSS flexbox layouts — the flexbox editor for trying alignment values
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.