Flex Items in Tailwind CSS
In the last chapter you controlled the flex container — direction, wrapping, and alignment. This chapter flips the focus onto the children themselves: how much they grow, how much they shrink, what size they start at, what order they appear in, and how to override one item's alignment without touching the rest. These are the utilities that turn a basic flex row into a polished, responsive layout.
What are Flex Items in Tailwind CSS?
Every direct child of a
flex container is a
flex item, and every flex item has three
independent dimensions that decide its final size:
grow (how eagerly it soaks up extra space),
shrink (how eagerly it gives up space when the
container is too small), and basis (its starting
size before growing or shrinking happens).
Rather than setting all three separately every time, Tailwind ships four shorthand classes that cover the vast majority of real layouts in one word.
flex: 1 1 0% — grows and
shrinks freely, ignoring its content size. The go-to class for
"fill whatever space is left".
flex: 1 1 auto — grows
and shrinks, but starts from its own content size instead of
zero.
flex: 0 1 auto —
Tailwind's default. Can shrink if needed, but never grows
beyond its content size.
flex: none — completely
rigid. Never grows, never shrinks, stays exactly its set size.
flex-1 first for
"fill the remaining space" columns, and
flex-none (usually paired with
a fixed width like w-64) for elements — sidebars,
avatars, icons — that should never change size no matter what.
Flex Grow & Flex Shrink
For finer control than the shorthand classes give you, Tailwind
exposes grow and
shrink independently — set one
without touching the other.
flex-grow: 1 — the item expands to consume any
leftover space in the container.
flex-grow: 0 — the item never grows past
its natural or basis size, even if space is left over.
flex-shrink: 1 — the item shrinks below
its basis size when the container is too small to fit
everyone.
flex-shrink: 0 — the item refuses to shrink, even
if it causes overflow. Essential for icons, avatars, and
fixed-width sidebars.
<!-- Fixed sidebar (never shrinks) + content that fills the rest -->
<div class="flex gap-4 h-40">
<div class="shrink-0 w-32 bg-purple-500 rounded-lg">Sidebar</div>
<div class="flex-1 bg-cyan-500 rounded-lg">Main content — fills whatever space is left</div>
</div>
<!-- Two equal-width columns -->
<div class="flex gap-4">
<div class="flex-1 bg-orange-500 rounded-lg p-4">Column A</div>
<div class="flex-1 bg-green-500 rounded-lg p-4">Column B</div>
</div>
Flex Basis — Starting Size
basis-* sets an item's size
before any growing or shrinking is applied. Think
of it as a smarter width that
flexbox is allowed to adjust from — it uses the same spacing scale
as w-*, plus fraction values
for column-style splits.
| Class | CSS Equivalent | Common use |
|---|---|---|
| basis-0 | flex-basis: 0px | Pair with grow for pure ratio-based sizing |
| basis-auto | flex-basis: auto | Default — size from content or width |
| basis-1/2 | flex-basis: 50% | Two equal-ish columns |
| basis-1/3 | flex-basis: 33.333% | Three-column starting size |
| basis-64 | flex-basis: 16rem | Fixed-width starting size (256px) |
| basis-full | flex-basis: 100% | Force an item onto its own line when wrapped |
basis-* wins over
w-* for a flex item's starting
size along the main axis — flexbox always computes layout from
flex-basis first, then applies
grow/shrink on top of it.
Order & Align-Self — Per-Item Overrides
These two utilities target a
single flex item rather than the whole container
— order changes where it
visually appears, and
self-* overrides its
cross-axis alignment.
order: 0.
order: -9999 — always renders
before every sibling.
order: 9999 — always renders after
every sibling.
order: 0.
align-items is set on the parent container.
<!-- Written 1, 2, 3 in HTML — rendered visually as 3, 1, 2 -->
<div class="flex gap-4">
<div class="order-2">Item 1</div>
<div class="order-3">Item 2</div>
<div class="order-1">Item 3</div>
</div>
<!-- Every card centred, except the featured one which stretches -->
<div class="flex items-center gap-4">
<div class="p-4 bg-gray-100 rounded-lg">Card</div>
<div class="self-stretch p-4 bg-cyan-500 text-white rounded-lg">Featured Card</div>
<div class="p-4 bg-gray-100 rounded-lg">Card</div>
</div>
Live Examples — See Flex Items in Action
These boxes are rendered with real Tailwind utility classes right on this page.
shrink-0 w-32 sidebar +
flex-1 content:
order-1 / order-2 / order-3
— visual order overriding markup order:
self-end breaking one item
away from items-center:
Common Real-World Use Cases
Flex item utilities are what turn a basic row into a layout that behaves exactly the way you want as content and screen size change.
shrink-0 w-64 on the
sidebar keeps it a fixed width no matter how little room is
left.
flex-1 on the main
content area automatically absorbs whatever space the fixed
elements don't use.
order-2 md:order-1
lets you write markup in a logical order and visually
rearrange it per breakpoint.
flex-1 spacer
between left and right groups pushes buttons apart without
needing justify-between.
flex-1 to
every child in a row forces them all to share
the available space equally.
self-start or
self-end on a single card
lets it opt out of the row's shared alignment.
Quick Reference — Flex Item Classes
| Class | CSS Equivalent | Description |
|---|---|---|
| flex-1 | flex: 1 1 0% | Grow and shrink freely, ignoring content size |
| flex-auto | flex: 1 1 auto | Grow and shrink from its own content size |
| flex-initial | flex: 0 1 auto | Default — can shrink, never grows |
| flex-none | flex: none | Never grows or shrinks — fully rigid |
| grow | flex-grow: 1 | Expands to consume leftover space |
| grow-0 | flex-grow: 0 | Default — never grows past natural size |
| shrink | flex-shrink: 1 | Default — shrinks when space is tight |
| shrink-0 | flex-shrink: 0 | Refuses to shrink, even causing overflow |
| basis-1/2 | flex-basis: 50% | Starting size before grow/shrink applies |
| basis-auto | flex-basis: auto | Default — size based on content/width |
| order-1 | order: 1 | Visual position, independent of DOM order |
| order-first | order: -9999 | Always renders before all siblings |
| order-last | order: 9999 | Always renders after all siblings |
| self-center | align-self: center | Overrides align-items for one item |
| self-stretch | align-self: stretch | Stretches just this item on the cross axis |
| self-auto | align-self: auto | Default — inherits the container's align-items |
- Every flex item has three independent sizing dimensions: grow, shrink, and basis.
-
Tailwind's shorthand —
flex-1,flex-auto,flex-initial,flex-none— covers most real layouts in one class. -
grow,shrink, andbasis-*give finer, independent control when the shorthand isn't enough. - order changes only the visual position of an item — the DOM and accessibility order stay untouched.
-
align-self overrides
align-itemsfor a single item, without affecting its siblings. -
Real patterns: fixed sidebars with
shrink-0, fill-remaining-space content withflex-1, and responsive reordering withorder-*. -
Next chapter moves into
CSS Grid — building two-dimensional layouts
with
grid-cols-*andgrid-rows-*.
Quick Check — Questions & Answers
Test your understanding of this chapter. Click a question to reveal the answer.
flex-1 is flex: 1 1 0% — the basis
is 0, so the browser pretends the item
starts at zero width and grows purely by its grow ratio
relative to siblings. flex-auto is
flex: 1 1 auto — the basis is
auto, so the item starts at its natural
content width and only then grows to fill remaining
space, meaning items with more text start out bigger.
shrink-0 plus a fixed width
like w-64, and give the main content
flex-1:<div class="flex"><aside class="shrink-0
w-64">...</aside><main
class="flex-1">...</main></div>Without
shrink-0, the sidebar would still
shrink below 256px if the viewport got narrow enough to
force it, since flex items shrink by default.
This matters for accessibility: screen readers and keyboard tab order follow the DOM, not the CSS
order value, so a sighted user and a
keyboard/screen-reader user can experience a different
sequence if you're not careful. Use order for
cosmetic rearrangement, not as a substitute for writing your
HTML in a sensible reading order to begin with.
self-* class directly to that one item —
it overrides whatever align-items is set on the
parent, without touching any sibling.Example:
<div class="flex
items-center"><div>Card</div><div
class="self-end">This one aligns to the
bottom</div></div>
— every other child stays vertically centred, only the one
with self-end breaks away.
MCQ Quiz — Test Yourself
Select the best answer for each question. Correct answers are revealed after you click.
Rate Us on Google
Join Our Learning Community
Connect with thousands of learners, get daily tips, ask questions and stay updated with new tutorials.