thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

06.04 · Layout with Flexbox / Learn + practice · 8 guided steps

Share space with grow, shrink and basis

Measure the difference between sharing spare space and giving space back when a row is too small.

Activity 4 of 5 in Layout with Flexbox

All courses

CSS Basics / 06.04

Share space with grow, shrink and basis

Not started

Measure the difference between sharing spare space and giving space back when a row is too small.

More options

Your lesson progress

Read & explore: not startedShare space in a flex sizing lab: not started

Empty: not started. Yellow: in progress. Green: complete. Marking the whole activity complete does not replace your test results. These circles save in this browser for this pilot.

Rob shares a fixed row of space between panels A, B and C with zero bases and grow factors 1, 2 and 1.
Rob’s comic strip · Layout with Flexbox

Read the three parts of flex

The shorthand flex: 1 1 0 means grow by 1, shrink by 1, with a zero starting basis. Grow factors share positive free space. With equal zero bases and no item padding or border, factors 1, 2, 1 produce widths in that ratio.

flex-basis is a starting main-axis size, not a promise of the final width. With nonzero bases, the final widths need not match the grow-factor ratio. Shrinking is weighted by the item bases, so shrink factors are not simple final-width ratios either.

Watch the measured widths

Start with a zero basis and a middle grow factor of 2. The middle panel receives two shares while the outside panels receive one each. Switch to 120px or 240px bases and compare the measured widths. Reduce the container width and toggle shrinking. If shrinking is off, the preview may need horizontal scrolling.

Change the middle grow factor, starting basis and shrink behavior. The labels show measured item widths.

styles.css

The changed declaration is highlighted. These controls do not edit or save your workshop code.

Main axis: left to right. Cross axis: top to bottom.

A
B
C

Content can set a lower limit

Flex items normally have an automatic minimum size. A long unbroken label may prevent the item from shrinking enough. min-width: 0 lets it become narrower, and overflow-wrap: anywhere lets a long label wrap. Use these deliberately when content should wrap rather than simply hiding overflow.

Build it one step at a time

Work through 8 small stages in the on-site editor. Read the instruction, make the requested change and run its checks. Your HTML and CSS carry forward; the preview updates as you type.

The workshop opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.

Start workshop(opens in a new tab)

8 steps · Saved work · Instant feedback

Keep useful documentation nearby

You do not need to memorize every property value. Read the task, predict the result, then use documentation to check your understanding.

Ready to try it?

Practice in your browser and see your results.

Progress details

Have a question?

Ask the Code Zone community.

Ask a question in The Code Zone (opens in a new tab)

Continue learning

ONE STEP FORWARD

Grow distributes extra space; shrink gives up space relative to bases; basis sets the starting main size.