Flexbox

Knowledge Videos

Short animated explainers, organised by subject.

Flexbox

Line up elements with display: flex. Flex container and flex items, justify-content, align-items, gap, flex-wrap and flex-direction.

Try it

Transcript

Flexbox is a way to line up elements. Put elements inside a container, and give the container display flex. Now its children, called flex items, sit in a row.

Justify content controls the space along the row. Flex start puts the items on the left, center puts them in the middle, and space between spreads them out.

Align items works across the row: top, center, or bottom. And gap adds space between the items.

When a row is full, items can overflow. Flex wrap moves them to the next line. And flex direction column stacks the items instead.

Remember: display flex makes a flex container. Use justify content, align items and gap to place its items.

More in this series