Loading lessons...
Flex Grow, Shrink & Basis
Flex Grow, Shrink & Basis
Control how individual flex items size themselves and consume free space.
Flex grow
Allow an item to grow to fill extra space:
<div class="flex">
<div class="grow">Grows to fill</div>
<div>Fixed</div>
</div>
grow- flex-grow: 1.grow-0- no growth (default).
Flex shrink
Allow an item to shrink when space is tight:
<div class="flex">
<div class="shrink">Can shrink</div>
</div>
shrink- flex-shrink: 1 (default).shrink-0- never shrink.
Flex basis
Set the initial size before growth/shrink:
| Class | CSS |
|---|---|
basis-0 | flex-basis: 0% |
basis-1/2 | 50% |
basis-64 | spacing scale |
basis-full | 100% |
basis-auto | auto |
<div class="basis-1/3">One third</div>
<div class="basis-1/3">One third</div>
<div class="basis-1/3">One third</div>
Flex shorthand
flex-<n> combines grow, shrink, and basis:
| Class | CSS |
|---|---|
flex-1 | 1 1 0% |
flex-auto | 1 1 auto |
flex-initial | 0 1 auto |
flex-none | 0 0 auto |
Order
Reorder items with order-<n>:
<div class="order-2">Second</div>
<div class="order-1">First</div>
Any integer works; order-none resets.
TL;DR
grow/grow-0control growth.shrink/shrink-0control shrinking.basis-1/2sets the initial size.flex-1,flex-auto,flex-noneare handy shorthands.order-<n>changes visual order.