How to use the flexbox generator
- Change the container properties on the left and watch the items move.
- Click an item to edit its own
flex-grow,flex-shrink,flex-basis,align-selfandorder. - 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) orcolumn(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.
centerwithjustify-content: centeris 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: 0stops an item, such as an icon or avatar, from getting squeezed.
Common flexbox patterns
- Navbar:
justify-content: space-betweenandalign-items: center. - Media object: a fixed image with
flex-shrink: 0next to text withflex: 1. - Sticky footer: a column flex body where the main element has
flex: 1. - Wrapping tags:
flex-wrap: wrapwith 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.