CSS flex Property
Description
The flex property is a shorthand applied to flex items that controls how an item sizes itself and participates in distributing available space inside a flex container. It bundles the behaviors that determine an item's base size, how it expands to fill extra room and how it contracts when space is limited, letting a single declaration express all three concerns. Because it is a per-item setting it only takes effect when the parent is a flex container created with display set to a flex mode.
The real power of flex appears in adaptive, proportional layouts: it operates along the container’s main axis (as determined by flex-direction) and participates in the sharing of free or oversubscribed space among sibling items. The constituent behaviors—linked to the corresponding longhands flex-grow, flex-shrink and flex-basis—establish how much an item contributes to or resists size changes and what its starting size should be before distribution takes place. That proportionality is what makes flex preferable to fixed widths for many responsive UI patterns.
When using flex in a layout, it’s important to coordinate it with alignment and spacing controls: distribution of leftover space along the main axis is typically handled by justify-content, cross-axis alignment by align-items, and consistent gaps between items by gap. You can also change visual sequencing with order without altering the source order. Finally, bear in mind that intrinsic item sizes and other constraints (for example min/max sizing) still influence final results, so flex should be used in combination with those constraints to produce predictable, accessible layouts.
Definition
- Initial value
- See individual properties
- Applies to
- Flex items, including in-flow pseudo-elements
- Inherited
- No
- Computed value
- See individual properties
- Animatable
- Yes
- JavaScript syntax
- object.style.flex
Interactive Demo
Syntax
flex: none | [ <flex-grow> <flex-shrink>? || <flex-basis> ]
Values
- noneCorresponds to the value of flex : 0 0 auto;
- autoCorresponds to the value of flex : 1 1 auto;
- initialSets the property to the default value. Corresponds to the value of flex : 0 1 auto;
- inheritIndicates that the value is inherited from the parent element.
- flex-basisA number that indicates how much the block will be increased in relation to the rest of the flex elements in the container. Negative values are not allowed. The default value is 0.
- flex-shrinkA number that indicates how much the block will be reduced in relation to other flex elements in the container (with a lack of free space). Negative values are not allowed. The default value is 1.
- flex-basisDefines the default size for the flex element before allocating space in the container. Negative values are not allowed. The size is indicated in CSS units (px, em, pt, etc.), or is calculated automatically by the browser based on the content of the element. The default value is auto.
Example
Browser Support
The following information will show you the current browser support for the CSS flex property. Hover over a browser icon to see the version that first introduced support for this CSS property.
This property is supported by all modern browsers.
Desktop
Tablets & Mobile
Last updated by CSSPortal on: 1st January 2026
