Skip to content
IndexRequest a UIAboutContact

Flex Alignment Playground

Buttons change flex direction and alignment on three boxes, with the CSS shown live.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Educational diagram showing a flex container as a dashed rectangle holding three coloured boxes of different heights, arrows along the main axis and the cross axis, four small panels in a grid illustrating justify-content values start, center, space-between and end, labels in clean monospace under each, flat vector style, light background, soft pastel boxes. Negative: gradients, shadows, text errors, clutter. Reduced motion: static diagram.

About this pattern

Definition

Flexbox lays items along a main axis. justify-content aligns them along that axis and align-items aligns them across it. Switching flex-direction swaps which axis is which, which is why the two properties seem to change places.

Purpose & UX principles

  • flex-direction: row or column sets the main axis.
  • justify-content: start, center, space-between or end along the main axis.
  • align-items: stretch, start, center or end across it.
  • gap sets spacing between items without margins.

Interaction states

  • Three button groups and a live CSS read-out.

Motion specification

  • Items move instantly.
  • Reduced motion: nothing animates.

Responsive behaviour

  • Use gap instead of margins on children.
  • To centre one thing both ways, set justify-content and align-items to center.

Code

HTML
<div class="bx"><div class="fx" id="fx"><i style="height:30px">1</i><i style="height:52px">2</i><i style="height:40px">3</i></div><div class="gp" id="gp"></div><pre class="cs" id="cs"></pre></div>

Related patterns

Masonry Columns Layout

↗
Masonry Columns LayoutLayout & Scrolling

Container Query Cards

↗
Container Query CardsLayout & Scrolling

Split Pane Resizer

↗
Split Pane ResizerLayout & Scrolling