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

Flexbox

Identify the flex container and items, follow their axes, and predict when a line can wrap.

Three controls in a toolbar need to stay together as their labels change length. Flexbox lets the browser arrange a group of items along one axis and share space between them.

Identify the container and its items

The element with display: flex becomes a flex container. Its in-flow child elements become flex items. If a control contains an icon and a label, the control is one item in the toolbar. The icon and label keep their own internal layout unless the control also establishes a layout for them.

The main axis runs in the direction the items are laid out. The cross axis runs across it. The initial flex direction is a row, so in horizontal, left-to-right text the controls run from left to right. Changing the direction to a column makes the main axis run from top to bottom in this writing mode.

Predict what happens at a narrow width

Start with enough space to fit all three controls on one row. Make the toolbar narrower. By default Flexbox keeps one line, and the controls can shrink until their size limits intervene. If they reach those limits, content can overflow.

Enable flex-wrap with the value wrap and a control that no longer fits can start a new line. If two controls still fit together, the third can move below them. Each line then shares its own available space. This distinction will matter when you size and align the items.

Three equal items fit across the wide row. The narrower container fits only the first two, so the third wraps below the first.

Key Takeaways

  • Apply Flexbox to the parent whose children should form the row or column.
  • Direction sets the main axis. Wrapping determines whether more flex lines can form.

Try it yourself

Try it yourself

Arrange a toolbar

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 lesson Measuring boxes and predicting their positionsNext lessonDirection and Wrapping
Edit on GitHubReport on GitHub
On this page
%

On this page

Identify the container and its itemsPredict what happens at a narrow widthKey TakeawaysTry it yourself