flex-shrink

Avatar of
on (Updated on )

UGURUS offers elite coaching and mentorship for agency owners looking to grow. Start with the free Agency Accelerator today.

The flex-shrink property is a sub-property of the Flexible Box Layout module.

It specifies the “flex shrink factor” which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the row.

.element {
  flex-shrink: 2;
}

When omitted, it is set to 1 and the flex shrink factor is multiplied by the flex basis when distributing negative space.

Syntax

flex-shrink: <number>

Demo

To see the full potential of this demo, you would have to be able to resize its width, so please have a look at it on CodePen directly.

In this demo:

  • The first item has flex: 1 1 20em (shorthand for flex-grow: 1, flex-shrink: 1, flex-basis: 20em)
  • The second item has flex: 2 2 20em (shorthand for flex-grow: 2, flex-shrink: 2, flex-basis: 20em)

Both flex items want to be 20em wide. Because of the flex-grow (first parameter), if the flex container is larger than 40em, the 2nd child will take twice as much leftover space as the first child. But if the parent element is less than 40em wide, then the 2nd child will have twice as much shaved off of it as the 1st child, making it look smaller (because of the 2nd parameter, flex-shrink).

Browser support

  • (modern) means the recent syntax from the specification (e.g. display: flex;)
  • (hybrid) means an odd unofficial syntax from 2011 (e.g. display: flexbox;)
  • (old) means the old syntax from 2009 (e.g. display: box;)
IEEdgeFirefoxChromeSafariOpera
10+All20+22+8+12.1+
iOSChrome AndroidFirefox AndroidAndroidOpera Mobile
8+AllAll92+12.1+
Source: caniuse

Blackberry browser 10+ supports the new syntax.

For more informations about how to mix syntaxes in order to get the best browser support, please refer to “Using Flexbox” or this article from DevOpera.

More information