CSS Flexbox Alignment & Justify Properties
Flexbox has six alignment properties spread across containers and items. Previous chapters introduced them individually — this chapter brings them all together: the full taxonomy, the shorthands that combine them, and the complete cookbook of centring and alignment recipes you will use every day.
justify-content — all 6 values
in depthalign-items — single-line
cross-axisalign-self — per-item
cross-axis overridealign-content — multi-line
cross-axisplace-items, place-self, place-contentThe Alignment Taxonomy
CSS alignment properties always operate along one of two axes. The table below maps every Flexbox alignment property to its axis, target, and where it's applied. Understanding this map removes all confusion:
* justify-self and justify-items have
no effect in Flexbox — use margin: auto to achieve
individual main-axis positioning of flex items.
| Property | Applies to | Axis | Effect | Default |
|---|---|---|---|---|
| justify-content | Container | Main | Distributes all items + free space | flex-start |
| align-items | Container | Cross | Aligns items in a single line | stretch |
| align-content | Container | Cross | Aligns multiple lines (wrap only) | normal |
| align-self | Item | Cross | Overrides align-items for one item | auto |
| place-items | Container | Both | Shorthand: align-items + justify-items* | normal |
| place-self | Item | Both | Shorthand: align-self + justify-self* | auto |
| place-content | Container | Both | Shorthand: align-content + justify-content | normal |
justify-content — Main Axis Distribution
justify-content distributes flex items and free
space along the main axis. It acts on the container. In flex-direction: row (default), this is horizontal distribution:
When flex-direction: column, justify-content
distributes items vertically:
Bonus: margin: auto — Since
justify-self doesn't work in Flexbox, use margin: auto on an item to push remaining space to one side:
Login has margin-left:auto — pushes it to the right, Login+SignUp stay together at end
.container { display: flex; }
.jc-start { justify-content: flex-start; } /* default */
.jc-end { justify-content: flex-end; }
.jc-center { justify-content: center; }
.jc-between { justify-content: space-between; }
.jc-around { justify-content: space-around; }
.jc-evenly { justify-content: space-evenly; }
/* margin:auto as per-item justify-self replacement */
.nav { display: flex; align-items: center; }
.nav .logo { }
.nav .login { margin-left: auto; } /* pushes to right edge */
/* Space-before one item in a column */
.footer-link { margin-top: auto; } /* pushes to bottom */
align-items — Cross Axis (Single Line)
align-items aligns all items along the
cross axis within a single flex line. Container has items with different heights so the
differences are visible. Default is stretch:
tall
tall
tall
tall
.container { display: flex; }
.ai-stretch { align-items: stretch; } /* default — fill height */
.ai-start { align-items: flex-start; } /* top */
.ai-end { align-items: flex-end; } /* bottom */
.ai-center { align-items: center; } /* ← use this most often */
.ai-baseline { align-items: baseline; } /* text baseline align */
/* Perfect centring */
.center-both {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
align-self — Per-Item Cross Axis Override
align-self lets one individual item override the
container's align-items. The container below has align-items: center. Each card shows one item with a different align-self value (green) while others remain centred (blue):
.container {
display: flex;
align-items: flex-start; /* default for all items */
}
/* One item overrides */
.special { align-self: center; }
.fill { align-self: stretch; }
/* ── Pattern: Card with CTA at the bottom ── */
.card {
display: flex;
flex-direction: column;
}
.card .cta {
margin-top: auto; /* pushes CTA to bottom */
align-self: flex-start; /* don't stretch button full width */
}
/* ── Pattern: Avatar stays at top in tall card row ── */
.card-row { display: flex; align-items: stretch; }
.card .avatar { align-self: flex-start; } /* top-aligns avatar */
align-content — Multi-Line Cross Axis
align-content aligns multiple flex
lines as a group within the container. It only takes effect when flex-wrap: wrap creates more than one line and the container has
extra cross-axis space. Each demo has a fixed height with 4 wrapped items:
align-items for the vast majority of cases — it works in both
single-line and multi-line containers and aligns items within each row. Only reach for align-content when you have flex-wrap: wrap, a taller container, and want to control how the rows as
a group are distributed in that extra vertical space.
place-items, place-self & place-content
CSS provides three shorthand properties that combine alignment pairs. Their behaviour
differs between Flexbox and Grid — in Flexbox the justify-* component
has limited effect:
place-content: center centres items on both axes at once.align-items part has effect.
justify-items is ignored for flex items.
align-self part has effect.
justify-self is ignored for flex items.
Live place-content demos on a flex container
with a fixed height — rows on a 3-column grid:
/* ── place-content: <align-content> [<justify-content>] ── */
.center-all {
display: flex;
place-content: center; /* both axes */
min-height: 100vh;
}
/* Different values for each axis */
.nav { place-content: center space-between; }
/* ↑align-content ↑justify-content */
/* ── place-items: <align-items> [<justify-items>] ── */
.container { place-items: center; }
/* In Flexbox: only align-items:center takes effect */
/* In Grid: both align-items and justify-items apply */
/* ── place-self: <align-self> [<justify-self>] ── */
.item { place-self: center; }
/* In Flexbox: only align-self:center takes effect */
/* RECOMMENDATION: in Flexbox use explicit properties
for clarity, save shorthands for Grid where they fully work */
Centring Cookbook — Recipes for Every Situation
These are the patterns you'll use constantly. All are pure Flexbox — no position tricks needed:
justify-content:center;
align-items:center;
min-height:100vh;
justify-content:center;
align-items:center;
min-height: Npx;
/* no justify-self needed */
justify-content:center;
align-items:center;
align-items:stretch; /* default */
Try It Yourself
All alignment properties in one editor. Try changing values and see how items respond.
Experiment with margin: auto, align-self overrides and place-content:
Quick Check — Chapter 28
justify-self (and justify-items)
have no effect on flex items by specification. In Flexbox, the main axis distribution is controlled at
the container level by justify-content — it distributes all items
together. There is no per-item main-axis positioning in the same way there is for the cross axis (align-self).The replacement:
margin: autoWhen you want to push one specific flex item or a group of items to a different position along the main axis, set
margin-left: auto or margin-right: auto. auto margins in
Flexbox absorb all available free space on that side.Examples:
— Logo left, login+signup right:
.login { margin-left: auto; }— Items left, one item pinned right:
.pinned { margin-left: auto; }— CTA pushed to bottom of a column card:
.cta { margin-top: auto; }
Classic (3 properties, most explicit):
display: flex;justify-content: center; (main axis)align-items: center; (cross axis)Compact (2 properties, using shorthand):
display: flex;place-content: center; (both axes)Both require the container to have a defined height — otherwise there's no vertical space to centre within. Use
min-height: 100vh for full-screen, height: Npx for fixed containers, or min-height: Npx for flexible containers.The classic form is preferred in teams for readability. The compact form is useful in prototyping or when writing concise utility classes.
flex-direction: column, the main axis is
vertical (top to bottom). So justify-content operates
vertically:justify-content: center → centres items vertically
in the containerjustify-content: space-between → distributes vertical space between
rowsAnd the cross axis is horizontal, so:
align-items: center → centres items
horizontallyThis is the axis rotation principle: properties don't change meaning, but the physical directions they control rotate with
flex-direction. Always think in terms of "main
axis" and "cross axis" rather than "horizontal" and "vertical".
flex-direction: column on the card and margin-top: auto on the CTA button:.card { display: flex; flex-direction: column; }.cta { margin-top: auto; }margin-top: auto absorbs all available free space above the CTA,
pushing it to the bottom regardless of how much content is above it. This is why cards in a grid with
different content lengths all have their CTAs aligned at the bottom.Often combined with:
align-self: flex-start on the CTA — so the button doesn't stretch to
full card width when align-items: stretch is active.This is the cleanest solution — no absolute positioning, no JavaScript height measurement needed.
place-content combines align-content + justify-content.
Both components work in Flexbox. This is the most useful shorthand in Flexbox for full centring: place-content: center.place-items combines align-items + justify-items. In
Flexbox, only the align-items part works — justify-items has no effect on flex items. So place-items: center in Flexbox only centres items on the cross
axis.place-self combines align-self + justify-self. In
Flexbox, only align-self works.Recommendation: in Flexbox use
place-content (it works fully). For
Grid, all three shorthands work completely as expected.
align-items: baseline align?flex-direction: column and
align-items: center. In which direction are items centred?
flex-direction: column. You
want the CTA button at the card bottom regardless of content height. What CSS should the CTA have?- Taxonomy: Main axis →
justify-content. Cross axis →align-items,align-self,align-content.justify-self/justify-itemshave no effect in Flexbox. justify-content— main axis:flex-start,flex-end,center,space-between,space-around,space-evenly. Rotates withflex-direction.margin: auto— the per-item main axis alignment technique in Flexbox.margin-left: autopushes an item to the right.margin-top: autopushes down in column containers.align-items— cross axis for all items in a line:stretch(default),flex-start,flex-end,center,baseline.align-self— overridesalign-itemsfor one item. Same values plusauto.align-content— cross axis for multiple lines (requiresflex-wrap: wrap+ extra height). Use only when you need line-group control.- Shorthands:
place-contentworks fully in Flexbox (align-content + justify-content).place-itemsandplace-selfonly affect the cross axis in Flexbox. - Perfect centring recipe:
display:flex; justify-content:center; align-items:center; min-height:100vh— or compact:display:flex; place-content:center. - CTA to bottom:
flex-direction: columnon card +margin-top: autoon CTA.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.