Skip to content

Understanding the flex: 1 Property in CSS

What is the flex: 1 Property?

The flex: 1 property is a shorthand property that sets the flex-grow, flex-shrink, and flex-basis properties to 1. It is used to make a flex item take up equal space in a flex container.

Flex Shrink

The flex-shrink property in CSS determines: how much a flex item will shrink relative to the other flex items within the same flex container when there isn’t enough space available.

Flex Grow

The flex-grow property in CSS defines how much a flex item will grow relative to the other items inside a flex container when there is extra space available along the main axis (either horizontal or vertical, depending on flex-direction) of the container

Flex Basis

The flex-basis property in CSS defines the initial size of a flex item before any available space is distributed. It can be a length (e.g., px, em, rem) or a percentage.

When to Use the flex: 1 Property?

Example

<div class="container">
  <div class="item">Item 1</div>
  <div class="item">Item 2</div>
  <div class="item">Item 3</div>
</div>
.container {
  display: flex;
}

.item {
  flex: 1;
}

Demo

https://codesandbox.io/p/sandbox/css-flex-1-3hmz99