SystemTutor
About
Sign in
Loading course documentation…
SystemTutor

COURSES

  • Data Structures & Algorithms
  • CSS MasterclassNew course
  • System DesignNew course

PRACTICE

  • Algorithm practice
  • CSS practice

LEGAL

  • Privacy Policy
  • Terms of Service
  • About

© 2026 SystemTutor. All rights reserved.

Built with 🫶 by Shatlyk

Welcome to CSS
FlexboxDirection and WrappingFlex Item SizingMain-Axis AlignmentCross-Axis AlignmentFlexbox PatternsDebugging Flexbox Sizing and aligning a flex layout
Flexbox Layouts

Flex Item Sizing

Control flex growth, shrinking, basis, and order.

Flexbox starts each item at a basis, or starting size. It then lets items grow to fill space or shrink to fit. The flex shorthand sets grow, shrink, and basis together.

Read the three values

.sizes {
  display: flex;
  width: 32rem;
}

.sizes > article {
  flex: 1 1 8rem;
  min-width: 0;
}

.sizes > .featured {
  flex: 3 1 8rem;
}

Assume two articles, with the second using class="featured":

PartMeaning in 1 1 8rem
flex-grow: 1Receives a share of positive free space.
flex-shrink: 1Can give up space when the items do not fit.
flex-basis: 8remStarts main-axis sizing from this basis.

The basis is not the final size. In a row, a basis such as 8rem supplies the starting size instead of width. With auto, the browser first checks the item’s main-size property. In this horizontal row it checks width. If that is also automatic, the content supplies the starting size.

Distribute growth

With a 16-pixel root font size and no gaps, padding, borders, or margins:

  1. The container is 512 pixels wide.
  2. Both bases are 128 pixels, leaving 256 pixels to share.
  3. Grow factors 1 and 3 divide that extra space into four shares of 64 pixels.
  4. The final widths are 192 pixels and 320 pixels.

Two 128px bases leave 256px to distribute. Grow factors 1 and 3 add 64px and 192px, producing final widths of 192px and 320px.

The featured item gets three times the extra space, not three times the final width. Equal grow factors also do not guarantee equal widths when starting bases differ. Size limits can constrain distribution.

Understand shrinking

.shrink {
  display: flex;
  width: 300px;
}

.shrink > article {
  flex: 0 1 200px;
  min-width: 0;
}

.shrink > .wide {
  flex-basis: 400px;
}

For two short articles, the bases total 600 pixels, creating a 300-pixel shortage. Both shrink factors are 1, but each factor is multiplied by that item's base size. The 200-pixel item loses 100 pixels; the 400-pixel item loses 200 pixels. Their final widths are 100 and 200 pixels, assuming no other size constraints.

min-width: 0 lets these row items shrink below the size their content would normally allow. Check that the text can still wrap or scroll.

Recognize useful combinations

  • flex: 0 1 auto: The initial combination; can shrink but does not grow.
  • flex: 1 1 auto: Can grow and shrink from an automatic basis.
  • flex: 1 1 0: Shares space from a zero basis, subject to minimum and maximum sizes.
  • flex: none: Expands to 0 0 auto; disables growing and shrinking.

Using all three values makes the intended basis explicit.

Treat visual order separately

.sizes > .featured {
  order: -1;
}

Lower order values appear earlier; the initial value is 0. Equal values follow source order. This changes visual order, not document order or the usual tab sequence. Keep meaningful reading and interaction order in HTML.

Check a growth calculation

Two items each start at 100px in a 400px row with no gaps. Their grow factors are 1 and 1. How much free space remains, and what is each final size?

Check your reasoning

The bases use 200px, leaving 200px. Each item receives 100px, so each finishes at 200px, assuming no size constraints.

If the second grow factor becomes 3, which size changes: its basis or its share of the extra space?

Check your reasoning

Its basis remains 100px. It receives three of the four shares of free space, giving final sizes of 150px and 250px.

Key Takeaways

  • Basis: Establishes the starting main size.
  • Growth: Shares extra space according to grow factors.
  • Shrinking: Uses shrink factors multiplied by base sizes.
  • Order: Changes visual placement while the source sequence stays meaningful.

Try it yourself

Try it yourself

Share extra space

HTML + CSS

Loading code editor…

Live preview

Updating…

Final output

No comparison yetChecks after 3s without edits
Loading your draft…

How is this lesson?

Previous lessonDirection and WrappingNext lessonMain-Axis Alignment
Edit on GitHubReport on GitHub
On this page
%

On this page

Read the three valuesDistribute growthUnderstand shrinkingRecognize useful combinationsTreat visual order separatelyCheck a growth calculationKey TakeawaysTry it yourself