Editor's Draft · css-flexbox

CSS Flexible Box Layout

8 properties defined by this specification, all known to at least one browser .

Each feature in detail

flex

Property Baseline: widely availablesince March 2018

MDN The flex CSS shorthand property sets how a flex item will grow or shrink to fit the space available in its flex container.

Live preview Example from MDN
.default-example {
  border: 1px solid #c5c5c5;
  width: auto;
  max-height: 300px;
  display: flex;
}

.default-example > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  margin: 10px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;
}

#example-element {
  background-color: rgb(255 0 200 / 0.2);
  border: 3px solid rebeccapurple;
}

Syntax

none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
0 1 auto
Applies to
flex items
Inherited
no
Percentages
see individual properties
Computed value
see individual properties
Canonical order
per grammar
Animation type
by computed value type
Longhands
flex-grow, flex-shrink, flex-basis

Browser support

First browser version supporting flex
Chrome 29
Edge 12
Firefox 22
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-basis

Property Baseline: widely availablesince March 2018

MDN The flex-basis CSS property sets the initial main size of a flex item. It sets the size of the content box unless otherwise set with box-sizing.

Live preview Example from MDN
.default-example {
  border: 1px solid #c5c5c5;
  width: auto;
  max-height: 300px;
  display: flex;
}

.default-example > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  margin: 10px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: auto;
}

Syntax

content | <'width'>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
auto
Applies to
flex items
Inherited
no
Percentages
relative to the flex container’s inner main size
Computed value
specified keyword or a computed <length-percentage> value
Canonical order
per grammar
Animation type
by computed value type

Browser support

First browser version supporting flex-basis
Chrome 29
Edge 12
Firefox 22
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-direction

Property Baseline: widely availablesince March 2018

MDN The flex-direction CSS property sets how flex items are placed in the flex container defining the main axis and the direction (normal or reversed).

Live preview Example from MDN
#example-element {
  border: 1px solid #c5c5c5;
  width: 80%;
  display: flex;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  width: 60px;
  margin: 10px;
}

Syntax

row | row-reverse | column | column-reverse

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
row
Applies to
flex containers
Inherited
no
Percentages
n/a
Computed value
specified keyword
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting flex-direction
Chrome 29
Edge 12
Firefox 22
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-flow

Property Baseline: widely availablesince March 2018

MDN The flex-flow CSS shorthand property specifies the direction of a flex container, as well as its wrapping behavior.

Live preview Example from MDN
#example-element {
  border: 1px solid #c5c5c5;
  width: 80%;
  max-height: 300px;
  display: flex;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  width: 60px;
  margin: 5px 10px;
}

Syntax

<'flex-direction'> || <'flex-wrap'>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
see individual properties
Applies to
see individual properties
Inherited
see individual properties
Percentages
see individual properties
Computed value
see individual properties
Canonical order
per grammar
Animation type
see individual properties
Longhands
flex-direction, flex-wrap

Browser support

First browser version supporting flex-flow
Chrome 29
Edge 12
Firefox 28
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-grow

Property Baseline: widely availablesince March 2018

MDN The flex-grow CSS property sets the flex grow factor, which specifies how much of the flex container's positive free space, if any, should be assigned to the flex item's main size.

Live preview Example from MDN
.default-example {
  border: 1px solid #c5c5c5;
  width: auto;
  max-height: 300px;
  display: flex;
}

.default-example > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  margin: 10px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 0;
}

Syntax

<number [0,∞]>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
0
Applies to
flex items
Inherited
no
Percentages
n/a
Computed value
specified number
Canonical order
per grammar
Animation type
by computed value type

Browser support

First browser version supporting flex-grow
Chrome 29
Edge 12
Firefox 20
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-line-count

Property Experimental

MDN The flex-line-count CSS property sets the minimum number of flex lines that flex items will be balanced over in cases where a flex container's flex-wrap or flex-flow property includes the balance keyword.

Live preview Example from MDN
#example-element {
  border: 1px solid #c5c5c5;
  width: 80%;
  display: flex;
  flex-wrap: wrap balance;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  width: 60px;
  margin: 10px;
}

Syntax

<integer [1,∞]>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
1
Applies to
multi-line flex containers
Inherited
no
Percentages
n/a
Computed value
the specified integer, computed
Canonical order
per grammar
Animation type
as integer

Browser support

First browser version supporting flex-line-count
Chrome 150
Edge 150
Firefox No
Safari No
Chrome Android 150
Safari iOS No

First version with support, from MDN browser-compat-data.

flex-shrink

Property Baseline: widely availablesince March 2018

MDN The flex-shrink CSS property sets the flex shrink factor of a flex item. If the size of all flex items is larger than the flex container, the flex items can shrink to fit according to their flex-shrink value. Each flex line's negative free space is distributed between the line's flex items that have a flex-shrink value greater than 0.

Live preview Example from MDN
.default-example {
  border: 1px solid #c5c5c5;
  width: auto;
  max-height: 300px;
  display: flex;
}

.default-example > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  margin: 10px;
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 300px;
}

Syntax

<number [0,∞]>

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
1
Applies to
flex items
Inherited
no
Percentages
n/a
Computed value
specified value
Canonical order
per grammar
Animation type
number

Browser support

First browser version supporting flex-shrink
Chrome 29
Edge 12
Firefox 20
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.

flex-wrap

Property Baseline: widely availablesince March 2018 Modern CSS: flex-wrap: balance

MDN The flex-wrap CSS property sets whether flex items are forced onto one line or can wrap onto multiple lines. If wrapping is allowed, it sets the direction that lines are stacked.

Live preview Example from MDN
#example-element {
  border: 1px solid #c5c5c5;
  width: 80%;
  display: flex;
}

#example-element > div {
  background-color: rgb(0 0 255 / 0.2);
  border: 3px solid blue;
  width: 60px;
  margin: 10px;
}

Syntax

nowrap | [ wrap | wrap-reverse ] || balance

Formal grammar from the specification, as webref extracts it: the latest level's definition, sometimes ahead of what browsers implement.

Definition

Initial
nowrap
Applies to
flex containers
Inherited
no
Percentages
n/a
Computed value
specified keyword
Canonical order
per grammar
Animation type
discrete

Browser support

First browser version supporting flex-wrap
Chrome 29
Edge 12
Firefox 28
Safari 9
Chrome Android 29
Safari iOS 9

First version with support, from MDN browser-compat-data.