Skip to content

CSS Tutorial CSS Flexbox

CSS flex-grow, flex-shrink and flex-basis

Lesson 96 of 182 2 min read By Deepak Paswan Updated Oct 4, 2026

These three properties are set on the items and decide how they share space.

flex-basis: the starting size

The size an item wants before any growing or shrinking. It works like width in a row (and like height in a column). The default is auto, which means “use my width or content size”.

flex-grow: share out extra space

If the container has leftover space, flex-grow says how much of it each item gets. The default is 0, which means “don’t grow”. Items share leftover space in proportion to their numbers.

index.html
HTML
<style>
  .container { background: #f4f9fc; border: 2px dashed #1a5276; padding: 8px; }
  .box { background: #d94a00; color: #fff; padding: 12px 18px; font-weight: bold; }
  .container { display: flex; gap: 6px; margin-bottom: 8px; }
  .box { text-align: center; }
  p { margin: 6px 0 2px; font-size: 13px; }
</style>
<p>No grow: items keep their size.</p>
<div class="container"><div class="box">1</div><div class="box">2</div><div class="box">3</div></div>
<p>flex-grow: 1 on each: equal shares.</p>
<div class="container">
  <div class="box" style="flex-grow:1">1</div><div class="box" style="flex-grow:1">2</div><div class="box" style="flex-grow:1">3</div>
</div>
<p>flex-grow: 1, 2, 1: the middle one gets double.</p>
<div class="container">
  <div class="box" style="flex-grow:1">1</div><div class="box" style="flex-grow:2">2</div><div class="box" style="flex-grow:1">3</div>
</div>

flex-shrink: give up space when it is tight

If the items together are wider than the container, flex-shrink decides how much each one gives up. The default is 1 (everyone shrinks). flex-shrink: 0 says “never shrink me”, which is handy for sidebars and icons.

The flex shorthand

The three are usually written as one: flex: grow shrink basis.

ShorthandMeaning
flex: 1Grow and share space equally, start from 0
flex: autoGrow and shrink from the item’s own size
flex: noneFixed: no grow, no shrink
flex: 0 0 200pxExactly 200px, never changes
flex: 1 1 240pxStarts at 240px, can grow and shrink
style.css
CSS
.sidebar { flex: 0 0 240px; }  /* fixed width */
.main    { flex: 1; }          /* takes everything else */

That is a classic sidebar layout in two lines.

warning
min-width and long content
A flex item cannot shrink below its content by default (min-width: auto). A long word or wide image can overflow the container. Add min-width: 0 to the item to allow shrinking.