flexbox

flex

Shorthand for flex-grow, flex-shrink, and flex-basis on a flex item. Controls how the item grows or shrinks to fill the flex container.

flex: none | auto | <flex-grow> <flex-shrink> <flex-basis>

Common values

Value Effect
0 1 auto Default; item can shrink but not grow
1 Equivalent to 1 1 0; item grows to fill space
auto 1 1 auto; grows and shrinks from its content size
none 0 0 auto; item is fully inflexible
1 1 0 Equal distribution regardless of content

Examples

.sidebar { flex: 0 0 250px; }

Fixed-width sidebar that will not flex

.main { flex: 1; }

Main region grows to fill remaining space

.card { flex: 1 1 240px; }

Cards flex from a 240px basis into equal columns

Gotcha

flex: 1 resets flex-basis to 0, which changes how content-based widths compute compared to flex: auto.

Related properties

← All CSS properties · CSS selectors · Grid vs Flexbox