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

Cross-Axis Alignment

Align flex items and lines on the cross axis.

The cross axis runs perpendicular to the main axis. For a row in horizontal writing, it runs vertically. Use align-items for all items, align-self for one item, and align-content for wrapped lines.

Align the items on a line

.toolbar {
  display: flex;
  min-height: 6rem;
  align-items: center;
  gap: 1rem;
}

In the initial row direction and a horizontal writing mode, this centers each item vertically within its flex line. A text label and a taller button can share a visual center without needing equal heights.

ValueCross-axis effect
stretchFills the line’s cross size when the item’s size is automatic, within its size limits.
flex-startAligns item margin boxes at cross-start.
flex-endAligns them at cross-end.
centerCenters them across the line.
baselineAligns their text baselines.

The initial normal alignment behaves as stretch for flex items. An item with an explicit cross size does not become that line's full size simply because stretching is enabled.

Override one item

.toolbar > .help {
  align-self: flex-end;
}

Add this rule to the toolbar example. The help item aligns at cross-end while its siblings keep the container's centered alignment. Put align-self on the item; align-items belongs on the container.

Set align-self: auto to follow the container’s align-items again. Here, that centers the help item alongside the others.

Distribute the flex lines

.tags {
  display: flex;
  flex-wrap: wrap;
  height: 12rem;
  align-items: flex-start;
  align-content: space-between;
  gap: 1rem;
}

With enough tags to form two lines, this separates the lines across the available height. align-items continues to align individual tags inside each line.

The same four tags form two flex lines. With flex-start the lines sit near the top. With space-between the lower line moves to the bottom, and the tops of C and D still align with each other.

Two conditions make the line distribution visible:

  • The container uses wrapping. align-content has no effect on a nowrap flex container.
  • There is spare space on the cross axis after the line sizes and gaps are accounted for.

Wrapping must be enabled, even if the items happen to fit on one line. With just one line, space-between has no lines to move apart.

Recheck the axis in a column

When flex-direction becomes column in a horizontal writing mode, the cross axis becomes horizontal. align-items: center then centers items horizontally, while justify-content controls the vertical main axis.

Choose the target of alignment

In the toolbar, you want only .help at cross-end while its siblings stay centered. Which property belongs on .help?

Check your reasoning

Use align-self: flex-end on .help. It overrides the container's align-items for that item.

Two wrapped tag lines need to be separated within a tall container. Would you change align-items or align-content? Why?

Check your reasoning

Use align-content on the container: it distributes lines. align-items positions items within their lines.

Key Takeaways

  • align-items: Sets cross-axis alignment for items on each line.
  • align-self: Overrides that alignment for one item.
  • align-content: Distributes lines in a wrapping flex container.
  • Axes: Cross-axis alignment changes orientation when flex direction changes.

Try it yourself

Try it yourself

Align one item differently

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 lessonMain-Axis AlignmentNext lessonFlexbox Patterns
Edit on GitHubReport on GitHub
On this page
%

On this page

Align the items on a lineOverride one itemDistribute the flex linesRecheck the axis in a columnChoose the target of alignmentKey TakeawaysTry it yourself