The flex property is a shorthand for flex-grow, flex-shrink, and flex-basis. It sets how a flex item grows or shrinks to fit space in its flex container.
Apply it to children of a display: flex (or inline-flex) container. For most layouts, MDN recommends auto, initial, none, or a positive unitless number such as 1.
Baseline · Widely available.
Not deprecated. Prefer the flex shorthand over setting the three longhands separately unless you need only one of them.
Syntax
CSS Syntax
syntax.css
flex:none | [ <grow> <shrink>? || <basis> ];
One value: a grow number (flex: 1 → 1 1 0%) or a basis (flex: 10em → 1 1 10em). Two or three values set grow, shrink, and/or basis in order.
Values
Property Values
Value
Description
Try it
initial
0 1 auto — no grow, can shrink, content-sized basis
Both start from 0% basis when you use a bare number.
Grow factors split free space.2 gets twice as much as 1.
Total parts = 3. First item ≈ 2/3, second ≈ 1/3 of the free space.
Resize the window in the editor to see the ratio hold.
Edge Cases & Pitfalls
If items will not grow or shrink as expected, check these first.
parent
Needs a flex container
flex only applies to flex items. Set display: flex on the parent first.
min
Items may not shrink below min-content
By default, items resist shrinking below their content. Use min-width: 0 (or min-height: 0) to allow tighter shrink.
shorthand
Omitted values are not always the initials
flex: 1 is 1 1 0%, not 1 1 auto. Prefer the shorthand values MDN lists for predictable results.
vs
flex vs width
A set width can fight with flex-basis. Prefer flex for flexible sizing; use width mainly with flex: none.
order
Visual order is not DOM order
order can rearrange items visually. Keep DOM order sensible for keyboard and screen-reader flow.
Compatibility
Browser Support
flex is a browser CSS property for flex items. Node.js, Deno, and Bun do not apply it.
✓ Baseline · Widely available
flex
Supported in all modern browsers. Older Internet Explorer needs the 2012 flexbox syntax in some cases.
97%Modern browser support
Google ChromeAll modern versions
Full support
Mozilla FirefoxAll modern versions
Full support
Apple SafariAll modern versions
Full support
Microsoft EdgeAll modern versions
Full support
OperaAll modern versions
Full support
Samsung InternetSupported
Full support
Internet ExplorerIE 11 (partial / older syntax)
Partial
flexWidely supported
Bottom line: Safe for modern flex layouts. Prefer the flex shorthand for grow/shrink/basis. It is not a runtime API.
Remember
Key Takeaways
Shorthand for grow, shrink, and basis on flex items.
Common picks:1, auto, none, initial.
flex: 1 → 1 1 0% for even flexible columns.
Parent first:display: flex, then flex on children.
One line: use flex on items to decide who grows, who shrinks, and from what starting size.
Frequently Asked Questions
It is a shorthand for flex-grow, flex-shrink, and flex-basis. It controls how a flex item grows, shrinks, and what size it starts from inside a flex container.
The initial value is 0 1 auto: the item does not grow, can shrink, and uses its content or width/height as the basis.
A unitless number expands to that grow factor with shrink 1 and basis 0%. So flex: 1 means 1 1 0%, which shares free space evenly with other similar items.
display: flex makes a flex container. The flex shorthand is set on flex items (the children) to control how each item uses space.
Use none (0 0 auto) when an item should keep its natural size and neither grow nor shrink, such as a logo or fixed control.
It is Baseline Widely available. It is a browser CSS layout property, not a Node.js runtime feature.