The flex property

flex is set on a flex item and defines how it shares space with its siblings: whether it grows, whether it shrinks and what size it starts from.

Syntax

flex: none | auto | <number> | <flex-grow> <flex-shrink> <flex-basis>;
flex: 1;          /* 1 1 0% */
flex: 1 1 220px;  /* grows, shrinks, base 220px */
Initial value
0 1 auto
Inherited
no
Applies to
flex items (direct children of a flex container)

Values

ValueWhat it does
none0 0 auto: does not grow or shrink — sized to its content
auto1 1 auto: grows and shrinks starting from its content size
<number>one number is a share of the free space: flex: 1 means 1 1 0%, and items with the same number get the same width
<grow> <shrink> <basis>the three values separately: flex-grow, flex-shrink and flex-basis

Example

.row {
  display: flex;
  gap: 8px;
}
.row div {
  padding: 12px;
  background: #e0f2fe;
  border: 1px solid #0284c7;
}
.a { flex: 1; }
.b { flex: 2; }
.c { flex: none; }
<div class="row">
  <div class="a">flex: 1</div>
  <div class="b">flex: 2</div>
  <div class="c">flex: none</div>
</div>

Result

▶ Open in HTML Editor

Good to know

  • flex is set on items, not on the container: the container needs display: flex.
  • flex: 1 and flex: auto differ: with 1 the base size is 0 and the width is shared equally; with auto the content width is taken first.
  • A flex item's minimum width is the width of its content, so a long word stops it from shrinking. min-width: 0 helps.

Sources and specification

See also