Flexbox

Also called flex, display: flex, or flexible box layout

A CSS layout mode that lines items up in a row or a column and controls how they share space, align, and wrap.

What is Flexbox?

Turn it on with display: flex on a parent, and its children line up along a main axis: a row by default, or a column with flex-direction: column. justify-content spreads them along that axis (start, center, space-between), and align-items positions them across it (top, middle, bottom, or stretched to fill).

Flexbox is the tool for one-dimensional layouts: navigation bars, button groups, a row of avatars, an icon next to a label, or centering something in a box with justify-content: center and align-items: center. Use gap for the space between items and flex-wrap: wrap to let them flow onto new lines.

When rows and columns need to line up with each other, such as a photo gallery or a page layout, CSS Grid is usually simpler. In Tailwind these map to classes like flex, flex-col, justify-between, items-center, and gap-4, which are handy words to use in prompts.

Often confused with

CSS Grid
Flexbox arranges items along one line at a time, a row or a column. CSS Grid places items on rows and columns at once, so they line up in both directions.
All terms

CSS Grid

A CSS layout system that places items on rows and columns at once, so content lines up in both directions.

Padding vs margin

Padding is the space inside an element’s border, around its content, while margin is the space outside the border that pushes other elements away.

Responsive design

Designing one layout that adapts to any screen width, rearranging columns, sizes, and navigation at set widths called breakpoints.

Layout animation

An animation that smoothly moves and resizes elements when the layout changes, such as list items gliding to new spots after a sort or filter.