Skip to content

CSS Flexbox Explained

Every common flexbox property, grouped by where it applies: the container and the item. Each row pairs the property with its common values and what it does.

Flexbox lays elements out in one dimension: a row or a column. Set display: flex on the parent and it becomes the flex container; its direct children become flex items. The container properties control distribution along the main axis and the cross axis; the item properties control how an individual item grows, shrinks, or aligns itself. Pick flexbox for one-dimensional bars, rows, and centring.

Reference table · 13 entries
13 of 13 rows
Container
flex | inline-flexTurn the element into a flex container.
row | column | row-reverse | column-reverseSet the main axis the items flow along.
flex-start | center | space-between | space-around | space-evenlyDistribute items along the main axis.
stretch | center | flex-start | flex-end | baselineAlign items along the cross axis.
flex-start | center | stretch | space-betweenAlign wrapped rows when there is extra space on the cross axis.
nowrap | wrap | wrap-reverseLet items wrap onto new lines instead of shrinking.
0.5rem | 8px 16pxSpace between items, horizontally and vertically.
Item
0 | 1 | 2How much free space the item absorbs relative to its siblings.
0 | 1How much the item shrinks when there is not enough space.
auto | 200px | 50%The starting size before free space is shared.
1 | 1 0 auto | 0 0 200pxShorthand for grow shrink basis.
auto | center | flex-start | flex-end | stretchOverride the container's align-items for one item.
0 | -1 | 2Reorder an item without changing the source.