Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Flex Shorthand | Layouts
Introduction to CSS Part II

bookFlex Shorthand

The flex shorthand property is a way to set the values of multiple flexbox properties in a single declaration. It can be used to set the flex-grow, flex-shrink, and flex-basis properties in a single line.

Here is a breakdown of each of the individual properties that can be set with the flex shorthand:

  • flex-grow. This property determines how much a flex item should grow relative to the other items in the container. It takes a numerical value, and the default value is 0. A value of 1 means the item will grow at the same rate as the other items in the container, while a value of 2 means it will grow twice as fast;

  • flex-shrink. This property determines how much a flex item should shrink relative to the other items in the container. It takes a numerical value, and the default value is 1. A value of 0 means the item will not shrink at all, while a value of 2 means it will shrink twice as fast as the other items;

  • flex-basis: This property sets the default size of a flex item along the main axis. It can be specified in any length unit (e.g., px, em, %), and the default value is auto.

Here's an example of using the flex shorthand property to set all three values at once:

.item {
  flex: 1 1 200px;
}

is equivalent to:

.item {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 200px;
}

Here's an example of using the flex shorthand property to set just the flex-grow value:

.item {
  flex: 2;
}

is equivalent to

.item {
  flex-grow: 2;
  flex-shrink: 1;
  flex-basis: 0%;
}

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 6

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookFlex Shorthand

The flex shorthand property is a way to set the values of multiple flexbox properties in a single declaration. It can be used to set the flex-grow, flex-shrink, and flex-basis properties in a single line.

Here is a breakdown of each of the individual properties that can be set with the flex shorthand:

  • flex-grow. This property determines how much a flex item should grow relative to the other items in the container. It takes a numerical value, and the default value is 0. A value of 1 means the item will grow at the same rate as the other items in the container, while a value of 2 means it will grow twice as fast;

  • flex-shrink. This property determines how much a flex item should shrink relative to the other items in the container. It takes a numerical value, and the default value is 1. A value of 0 means the item will not shrink at all, while a value of 2 means it will shrink twice as fast as the other items;

  • flex-basis: This property sets the default size of a flex item along the main axis. It can be specified in any length unit (e.g., px, em, %), and the default value is auto.

Here's an example of using the flex shorthand property to set all three values at once:

.item {
  flex: 1 1 200px;
}

is equivalent to:

.item {
  flex-grow: 1;
  flex-shrink: 1;
  flex-basis: 200px;
}

Here's an example of using the flex shorthand property to set just the flex-grow value:

.item {
  flex: 2;
}

is equivalent to

.item {
  flex-grow: 2;
  flex-shrink: 1;
  flex-basis: 0%;
}

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 6
some-alt