CSS Flexbox Item Properties
The previous chapter covered all the container properties. This chapter covers the other half — properties applied to individual flex items (the children). These control how each item sizes itself, whether it can grow or shrink, how it overrides the container's alignment, and its visual order.
flex-grow — distribute free
spaceflex-shrink — control shrinking
flex-basis — set the starting
sizeflex shorthand —
grow/shrink/basis in onealign-self — override
cross-axis alignmentorder — change visual order
All Flex Item Properties — Quick Reference
These 6 properties are applied to individual flex items (children of a flex container). They override or extend what the container sets:
flex: 1.align-items value for
this item only.flex-grow — Distributing Free Space
flex-grow defines how much an item grows
to fill available free space relative to its siblings. The value is a unit-less number — a ratio.
0 (default) means do not grow.
/* flex-grow: <number> — default 0 */
.item-a { flex-grow: 0; } /* don't grow (default) */
.item-b { flex-grow: 1; } /* grow to fill free space */
.item-c { flex-grow: 2; } /* grows twice as much as item-b */
/* How it works:
Total grow units = sum of all flex-grow values
Each item gets: (its grow / total) × free space
Example: A=1, B=2, C=1 → total=4
Free space = 120px
A gets: 1/4 × 120 = 30px extra
B gets: 2/4 × 120 = 60px extra
C gets: 1/4 × 120 = 30px extra */
/* Common pattern: fill remaining space */
.nav { display: flex; }
.nav .spacer { flex-grow: 1; } /* push items to edges */
flex-shrink — Controlling Shrinkage
flex-shrink defines how much an item
shrinks relative to its siblings when there is not enough space. Default is 1 (items shrink proportionally). 0 means
never shrink — the item will overflow before shrinking.
Each item shrinks the same amount to fit container
B shrinks more than A and C
B keeps its width, A and C absorb all shrinkage
Sidebar stays 80px, main content is flexible
/* flex-shrink: <number> — default 1 */
.item { flex-shrink: 1; } /* shrinks (default) */
.no-shrink { flex-shrink: 0; } /* never shrinks */
.more-shrink { flex-shrink: 3; } /* shrinks 3× as much */
/* Common patterns */
/* Avatar + text row — avatar stays fixed */
.avatar { flex-shrink: 0; width: 48px; }
.text { flex-shrink: 1; min-width: 0; }
/* Fixed sidebar layout */
.sidebar { flex-shrink: 0; width: 260px; }
.main { flex-shrink: 1; min-width: 0; }
/* ⚠ Always add min-width:0 on shrinking text items
to allow text-overflow:ellipsis to work correctly */
flex-basis — Setting the Starting Size
flex-basis sets the item's initial
main-axis size before any growing or shrinking happens. In a row container it acts like width. In a column container it acts like height.
Items size to their content
All start at 0, grow equally → equal widths
Each starts at 120px
Three equal columns
/* flex-basis: <length> | percentage | auto | 0 | content */
.item { flex-basis: auto; } /* default — size to content */
.item { flex-basis: 0; } /* start at zero (used with flex-grow) */
.item { flex-basis: 200px; } /* fixed starting width */
.item { flex-basis: 33.33%; } /* percentage of container */
.item { flex-basis: content; } /* size to content (like auto) */
/* flex-basis vs width:
- In a row container: flex-basis sets the initial WIDTH
- flex-basis takes precedence over width when both are set
- In a column container: flex-basis sets initial HEIGHT */
/* auto vs 0:
auto → item starts at its content size, then grows/shrinks
0 → item starts at zero, then grows proportionally
0 with flex-grow:1 = perfectly equal columns */
flex — The Shorthand You'll Use Most
The flex property is a shorthand for flex-grow, flex-shrink, and flex-basis in that order. In practice, you will almost always use one of
these preset values rather than setting all three separately:
/* flex: <grow> <shrink> <basis> */
.item { flex: 1; } /* grow:1 shrink:1 basis:0 ← most used */
.item { flex: auto; } /* grow:1 shrink:1 basis:auto */
.item { flex: none; } /* grow:0 shrink:0 basis:auto (rigid) */
.item { flex: 0 0 200px; } /* fixed 200px, won't grow or shrink */
.item { flex: 1 1 250px; } /* min 250px, grows and shrinks */
.item { flex: 2; } /* gets 2× free space vs flex:1 siblings */
/* ── Practical patterns ── */
/* Equal columns */
.col { flex: 1; }
/* Sidebar + main layout */
.sidebar { flex: 0 0 260px; } /* fixed sidebar */
.main { flex: 1; } /* main fills rest */
/* Responsive cards */
.card { flex: 1 1 300px; max-width: 400px; }
/* Avatar in a row — avatar stays fixed */
.avatar { flex: none; width: 48px; }
.content { flex: 1; min-width: 0; }
| Value | Expands to | Effect | Use when |
|---|---|---|---|
| flex: 1 | 1 1 0 | Equal columns, fills all space | Equal-width layout columns |
| flex: auto | 1 1 auto | Grow/shrink from content size | Nav links with equal spacing |
| flex: none | 0 0 auto | Stays at content size always | Fixed elements (avatars, icons) |
| flex: 0 0 Npx | explicit | Fixed Npx, no flexibility | Sidebar with exact width |
| flex: 1 1 Npx | explicit | Min Npx, grow and shrink | Responsive cards with min-width |
| flex: N | N 1 0 | N× more free space than flex:1 | Proportional columns (2:1:1) |
align-self — Override Cross-Axis Alignment
align-self overrides the container's align-items value for a single specific item. The container
sets the default alignment for all items — align-self lets one item be
different. All other items align as normal:
.container {
display: flex;
align-items: center; /* default for all items */
}
.item-a { } /* inherits center */
.item-b { align-self: flex-start; } /* overrides — goes to top */
.item-c { align-self: flex-end; } /* goes to bottom */
.item-d { align-self: stretch; } /* fills cross axis height */
.item-e { align-self: baseline; } /* aligns by text baseline */
.item-f { align-self: auto; } /* default — inherits container */
/* Real use: pull one card to bottom of a row */
.card-row { display: flex; align-items: flex-start; }
.cta-button { align-self: flex-end; margin-top: auto; }
order — Changing Visual Order
The order property changes the visual
order of flex items without modifying the HTML. Items with lower order values appear first.
Default is 0 — all items appear in DOM order.
order:0
order:0
order:0
order:0
order:3 → last
order:1 → 1st
order:4 → last
order:2 → 2nd
Orange(order:1) → Green-purple(order:2,3) → Blue(order:3) → Green(order:4)
order:0
order:0
order:-1
order:0
/* order: <integer> — default 0 */
.item-a { order: 0; } /* default */
.item-b { order: -1; } /* appears first (before 0) */
.item-c { order: 1; } /* appears after 0 items */
.item-d { order: 2; } /* appears last */
/* Real use: reverse column for mobile
sidebar appears below content on small screens */
@media (max-width: 640px) {
.container { flex-direction: column; }
.sidebar { order: 2; } /* after main content */
.main { order: 1; } /* main content first */
}
/* ⚠ Accessibility warning:
order changes visual order but NOT tab order (keyboard navigation)
and NOT reading order for screen readers. Tab/read order
still follows DOM order. Use only when visual reorder is
cosmetic — not for content that changes meaning by order. */
order property only changes the visual order. Keyboard
navigation (Tab key) and screen readers still follow the DOM order. This creates
a mismatch that can confuse keyboard and assistive technology users. Only use order for cosmetic reordering — for example pushing a decorative element to
the end. Never use it for content where reading order matters.
Try It Yourself
Experiment with flex item properties. Try changing flex-grow ratios, setting flex-shrink:0
on individual items, using different flex shorthand values and
reordering with order:
Quick Check — Chapter 27
flex-grow — controls how items expand to
fill available free space when the container is larger than the combined size of all items.
Default is 0 — items don't grow. When set to a positive number,
items take a proportional share of the leftover space. If A=1 and B=2, B gets twice as much of the free
space as A.flex-shrink — controls how items shrink
when the container is smaller than the combined size of all items. Default is 1 — items shrink proportionally. 0
means the item will never shrink — it will overflow before shrinking. Higher values mean the item
absorbs more of the overflow by shrinking more.They work in opposite scenarios: grow handles abundance of space, shrink handles shortage of space.
flex: 1 expands to flex-grow: 1; flex-shrink: 1; flex-basis: 0.It's commonly used because it creates perfectly equal-width columns that fill all available space:
—
flex-basis: 0 means all items start at zero width (ignoring their
content size)—
flex-grow: 1 means all items grow equally from that zero
baseline— The result: regardless of content length, all items end up exactly the same width
This is different from
flex: auto (= 1 1 auto) where items start at their content size before distributing
leftover space — so items with longer content end up wider.Use
flex: 1 when you want truly equal columns. Use flex: auto when you want items to be proportional to their content.
flex-basis: auto — the item starts at its natural
content size (or its set width/height). Flex grow/shrink then distributes the leftover space
after content sizes are accounted for. Items with more content naturally take up more space.flex-basis: 0 — the item starts at zero width
(ignoring content). Flex grow then distributes all the available space from scratch. When
combined with equal flex-grow values, all items end up exactly equal
width regardless of their content size.Example: Three items with content "A", "A long title", "B".
— With
flex: auto (= auto basis): widths are proportional — "A long
title" takes more space.— With
flex: 1 (= basis 0): all three items are exactly equal width.
align-items is a container property — it
sets the cross-axis alignment for all items in the container simultaneously.align-self is an item property — it
overrides the container's align-items value for one specific
item. All other items continue to follow the container's align-items value.Use case: a row of cards where all cards align to the top (
align-items: flex-start), but one special "featured" card should stretch
to full height (align-self: stretch) or a CTA button pushed to the
bottom (align-self: flex-end).Possible values: same as
align-items — auto (inherits, default), stretch,
flex-start, flex-end, center, baseline.
order changes the visual order of flex items
without modifying the HTML structure. Items with lower order values
appear first. The default is 0 for all items (DOM order). Negative
values move items before everything with order 0.Accessibility limitation: The
order property only
changes visual order. The keyboard Tab navigation order and screen reader reading
order still follow the DOM order (the HTML source order). This creates a disconnect —
sighted users see one order, but keyboard users and screen reader users experience a different
order.This mismatch violates WCAG 1.3.2 (Meaningful Sequence) and 2.4.3 (Focus Order). As a result,
order should only be used for purely cosmetic reordering where the
sequence doesn't affect meaning — for example, pushing a decorative icon to the end of a row. Never use
it for content where the reading or interaction sequence matters.
flex-grow: 1, flex-grow: 2, flex-grow: 1. There is
120px of free space. How much extra space does the second item receive?flex-shrink: 0 do to an item?flex: none expand to?align-items: flex-start. One
item has align-self: center. What happens?order: -1. What happens?flex-grow(default: 0) — how much an item expands to fill free space.0= don't grow. Values are ratios: grow:2 gets twice as much as grow:1.flex-shrink(default: 1) — how much an item shrinks when space is tight.0= never shrink. Always addmin-width: 0on shrinking text items for truncation to work.flex-basis(default: auto) — initial main-axis size.auto= content size.0= start at zero (equal columns when combined with grow:1). Takes precedence overwidth.flexshorthand:flex: 1= (1 1 0) equal columns.flex: auto= (1 1 auto) proportional.flex: none= (0 0 auto) rigid.flex: 0 0 200px= fixed 200px.align-self— overrides the container'salign-itemsfor one specific item. Values:auto(default),stretch,flex-start,flex-end,center,baseline.order(default: 0) — changes visual order. Lower numbers first. Negative values appear before 0. Accessibility warning: DOM order (tab/read order) is unchanged.- Sidebar layout:
sidebar { flex: 0 0 260px; }+main { flex: 1; min-width: 0; } - Equal columns:
flex: 1on all items.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.