Course contentsShow
← Web Development
Lesson 256 of 2,9825. FlexboxFree lesson

The Main Axis and Cross Axis

Learning the two perpendicular axes that govern all flexbox layout behavior.

The Main Axis and Cross Axis

You'll learn: How flexbox uses two perpendicular axes to control the direction and alignment of flex items.

Every flex container operates on two axes that work together to organize your layout. Think of them like the lines on graph paper—one horizontal and one vertical—but which is which depends on how you arrange your items.

The Main Axis

The main axis is the primary direction your flex items flow. By default (when you apply display: flex), the main axis runs left to right—items line up in a row. This is the "reading direction" of your flex container.

The main axis has a start point (main-start) and an end point (main-end). Items flow from main-start to main-end.

The Cross Axis

The cross axis runs perpendicular (at a 90-degree angle) to the main axis. If your main axis is horizontal, the cross axis is vertical (top to bottom).

The cross axis also has a start (cross-start) and end (cross-end). This axis controls how items align in the direction across their flow.

Why This Matters

These two axes are fundamental to understanding flexbox. Every flexbox property you'll learn targets either the main axis or the cross axis. Properties that control spacing along the row affect the main axis; properties that control vertical alignment affect the cross axis.

Analogy: Imagine organizing books on a shelf. The main axis is the direction you're placing books (left to right). The cross axis is how tall the shelf is (bottom to top).

Key Takeaway: Flexbox layouts are governed by two perpendicular axes—the main axis (primary flow direction) and the cross axis (perpendicular to flow)—and understanding which axis you're working with is essential for controlling your layout.