CSS <flex> Data Type
The <flex> data type is a flexible size in grid layout, written with the unit fr, such as 1fr. It shares out the free space in a grid container.
Description
The <flex> CSS data type represents a flexible length in a grid layout, written as a number followed by the unit fr (fraction), for example 1fr or 2.5fr. It is used to size grid tracks in grid-template-columns, grid-template-rows, grid-auto-columns and grid-auto-rows, and as the maximum in minmax(). Despite the name, it is not related to the flex property used in flexbox.
An fr value is a share of the free space in the grid container: the space left over after fixed-size tracks (such as 200px), content-sized tracks and gaps have been taken out. The free space is divided between the flexible tracks in proportion to their fr values, so 1fr 2fr gives the second column twice as much space as the first, and 200px 1fr gives the second column everything that is left after the 200px sidebar.
A flexible track still respects the minimum size of its content by default, because 1fr behaves like minmax(auto, 1fr). That is why a column containing a long word or a wide image can grow beyond its share. To let a flexible track shrink below its content size, use minmax(0, 1fr). <flex> values cannot be negative, and they cannot be combined with other units in calc().
Examples:
/* Three equal columns */
.grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr; /* same as repeat(3, 1fr) */
}
/* Fixed sidebar, flexible main area */
.layout {
display: grid;
grid-template-columns: 240px 1fr;
}
/* Middle column gets twice the space */
.weighted {
grid-template-columns: 1fr 2fr 1fr;
}
Interactive Demo
Syntax
<flex> = <number [0,∞]>fr
Values
- frA fraction of the free space in the grid container. The free space is shared between all flexible tracks in proportion to their <number> values. The number must not be negative.
Example
Browser Support
The following information will show you the current browser support for the CSS flex data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.
Desktop





Tablets & Mobile





