Skip to content

CSS Flexbox Generator & Playground

Learn and generate CSS flexbox layouts: try flex-direction, wrap, justify-content, align-items and gap on live items, edit grow, shrink and order, and copy CSS, Tailwind or Bootstrap classes.

Container

Click an item to edit its own flex properties.

Code

How to use the flexbox generator

  1. Change the container properties on the left and watch the items move.
  2. Click an item to edit its own flex-grow, flex-shrink, flex-basis, align-self and order.
  3. Copy the result as CSS, Tailwind classes or Bootstrap 5 utility classes.

Flexbox properties explained

  • flex-direction sets the main axis: row (left to right) or column (top to bottom).
  • justify-content distributes items along the main axis: start, center, end or with space between them.
  • align-items aligns items on the cross axis. center with justify-content: center is the classic way to center something.
  • flex-wrap lets items move to a new line when they do not fit; align-content then positions those lines.
  • gap adds space between items without extra margins.
  • flex: 1 1 0% on an item makes it grow and fill the remaining space; flex-shrink: 0 stops an item, such as an icon or avatar, from getting squeezed.

Common flexbox patterns

  • Navbar: justify-content: space-between and align-items: center.
  • Media object: a fixed image with flex-shrink: 0 next to text with flex: 1.
  • Sticky footer: a column flex body where the main element has flex: 1.
  • Wrapping tags: flex-wrap: wrap with a small gap.

For two-dimensional layouts, use the CSS grid generator. Bootstrap's d-flex utilities and Tailwind's flex classes map one to one to these properties; see them in action in our navbar components.

More CSS tools