Flex Layout Property

Last updated: 2026-09-13

flex Flex Layout Property

The flex property is the core shorthand of the CSS Flexible Box Layout module. It sets how a flex item grows, shrinks, and how much space it occupies relative to the remaining space in the container. It is a shorthand for flex-grow, flex-shrink and flex-basis, which control the item’s growth factor, shrink factor and initial main size. With flex, common layouts such as equal-width columns, fluid widths and flowing arrangements are easy to build.

Category
Initial Value0 1 auto
InheritedNo
Applies Toflex-items
Animation Typelength
CSS VersionCSS3
StatusStandard

📝 Syntax

flex: none | auto | initial | <flex-grow> <flex-shrink>? <flex-basis>?;

⚙️ Values

ValueTypeDescription
none | auto | initialKeywordPredefined flex values
<flex-grow> <flex-shrink>? <flex-basis>?ValueFlex grow/shrink/basis values

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
flex v29 v12 v28 v9 v17
Supported in all major browsers
Tip: flex: 1; is shorthand for flex: 1 1 0%. The item can grow and shrink and starts from a base size of 0, which is the typical way to make items share the remaining space equally.
Warning: flex: none; is equivalent to flex: 0 0 auto. The item neither grows nor shrinks and is sized purely by its content or an explicit width/height. Use it for fixed-size sidebars or buttons.

❓ FAQ

QWhat is the difference between flex: 1 and flex: auto?
Aflex: 1 is shorthand for flex: 1 1 0%. The base size is 0, so the whole width is redistributed proportionally and multiple flex: 1 items come out strictly equal width. flex: auto is shorthand for flex: 1 1 auto: each item is first sized from its content or width, then the leftover space is shared proportionally, so items with more content take more room. Use flex: 1 for equal-width splits and flex: auto when you want sizes to follow the content.
QWhen should I use the flex shorthand instead of the individual sub-properties?
AIn most cases the flex shorthand is the better choice because it sets flex-grow, flex-shrink and flex-basis in one declaration and avoids the surprise of flex-basis falling back to the default 0 when you only write flex-grow. It also communicates intent at a glance, making the base size explicit and easier to review than three scattered declarations. Use the longhand properties only when you need to override a single sub-property, for example changing only flex-basis inside a media query.
QWhy does text inside flex: 1 items wrap or get squashed?
AThis is caused by the default min-width: auto of flex items: when space runs out, the minimum size of an item is derived from its content, so long text keeps the item wide and the text wraps or overflows. Fix it by setting min-width: 0 on the item (min-height: 0 for the column direction) and combine it with overflow: hidden and text-overflow: ellipsis to get a single-line truncation.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏