Skip to content
Back to Concepts
CSS UniverseTrack 3: Flexbox & GridFlexbox Visualizer
1st Year CS Foundation ยท Core Track 3Core Concept 10

Flexbox Layout Studio

1-Dimensional layout powerhouse. Master Main Axis vs Cross Axis, justify-content, align-items, flex-grow, and the legendary CSS 1-line vertical centering trick.

1. The Core Mental Model

Main Axis vs Cross Axis (The Secret to Flexbox)

The single biggest mistake 1st-year students make is thinking justify-content always controls horizontal alignment. It doesn't!

justify-content = Aligns along MAIN Axis

If flex-direction: row, Main Axis is horizontal (left-to-right).
If flex-direction: column, Main Axis switches to vertical (top-to-bottom)!

align-items = Aligns along CROSS Axis

Cross Axis is always perpendicular (90 degrees) to the Main Axis.
Default value is stretch (items expand to match tallest item!).

2. Live Flexbox Axis Studio

Rotate Axes & Test Alignments Live

Item 1
Item 2
Item 3
3. The Holy Grail Center

Perfect Vertical & Horizontal Centering

/* Center anything perfectly inside its container: */
.parent {
display: flex;
justify-content: center; /* Main axis center */
align-items: center; /* Cross axis center */
}
4. Full Flexbox Workbench

Interactive Flexbox Visualizer

Interactive Lab

Advanced Flexbox Studio

Experiment with container axes, multi-line wrapping, and click any item to customize flex-grow, flex-shrink, flex-basis, align-self, and order.

Items Count (5)
Container Properties
flex-direction
flex-wrap
Item 2 PropertiesClick item to select
flex-grow0
flex-shrink1
order0
Main Axis: row (justify-content)Cross Axis (align-items)
Item 1
Item 2
Item 3
Item 4
Item 5

Click any block to adjust individual flex-grow, align-self, or order.

.flex-container { display: flex; flex-direction: row; justify-content: space-between; align-items: center; flex-wrap: wrap; align-content: stretch; gap: 16px; }
Next in Track 3

11. CSS Grid

2-Dimensional grid tracks, fr units, minmax, auto-fit vs auto-fill, and grid-template-areas.

Continue to CSS Grid