Favorites

CSS <flex> Data Type

<flex>
CSS Data TypeThis data type is supported by all modern browsers.
Updated 21st November 2026

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.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

One
Two
Three
Demo Code
HTML Code
<div class="demo-element">
	<div>One</div>
	<div>Two</div>
	<div>Three</div>
</div>
CSS Code
.demo-element > div {
	padding: 10px 12px;
	background: #4361ee;
	color: #fff;
	font-size: 14px;
	font-weight: bold;
}
.demo-element {
	display: grid;
	width: 300px;
	gap: 6px;
	padding: 6px;
	box-sizing: border-box;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
	grid-template-columns: 1fr 1fr 1fr;
}

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

<div class="wrap">
<h1>CSS &lt;flex&gt; examples</h1>
<div class="card">
<div class="g equal"><div>1fr</div><div>1fr</div><div>1fr</div></div>
<div class="label">grid-template-columns: 1fr 1fr 1fr</div>
<div class="g weighted"><div>1fr</div><div>2fr</div><div>1fr</div></div>
<div class="label">grid-template-columns: 1fr 2fr 1fr</div>
<div class="g mixed"><div>150px</div><div>1fr</div><div>2fr</div></div>
<div class="label">grid-template-columns: 150px 1fr 2fr</div>
</div>
<p class="note">Resize the window: the fr columns share whatever space is left.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
  margin: 24px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
  background: #f5f7fb;
  color: #102a43;
}

.wrap {
  max-width: 860px;
  margin: 0 auto;
}

h1 {
  font-size: 20px;
  margin: 0 0 16px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
  font-size: 12px;
  color: #486581;
  margin-top: 10px;
  word-break: break-word;
}

.note {
  font-size: 13px;
  color: #486581;
  margin-top: 14px;
}

/*  examples */
.g {
  display: grid;
  gap: 8px;
  margin-bottom: 6px;
}

.g div {
  padding: 14px 6px;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

.equal { grid-template-columns: 1fr 1fr 1fr; }
.weighted { grid-template-columns: 1fr 2fr 1fr; }
.mixed { grid-template-columns: 150px 1fr 2fr; }
.mixed div:first-child { background: #7c3aed; }
Open in editor

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.

This data type is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.