flex-shrink

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.

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>

.flex-item {
  flex-shrink: 2;
}

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.

Check out this Pen!

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).

Related Properties

Other Resources

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;)
Chrome Safari Firefox Opera IE Android iOS
21+ (modern)
20- (old)
3.1+ (old) 2-21 (old)
22+ (new)
12.1+ (modern) 10+ (hybrid) 2.1+ (old) 3.2+ (old)

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 this article (CSS-Tricks) or this article (DevOpera).

Comments

  1. User Avatar
    Drake Leung
    Permalink to comment#

    I’ve read the spc. But I don’t understand it without the demos, so I go to here. However, I don’t know why the demo has this effect. How does it copute? :(

  2. User Avatar
    Jason Pease
    Permalink to comment#

    This is not working on Ipad Safari v8.1.3. although it says its supposed to be compatible.

  3. User Avatar
    Jason Pease
    Permalink to comment#

    This isn’t working for Ipad Safari v8.1.3 although it is supposed to be compatible.

  4. User Avatar
    Roman Axelrod
    Permalink to comment#

    Not working with Safari 5.1.7

Submit a Comment

Posting Code

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.

icon-anchoricon-closeicon-emailicon-linkicon-logo-staricon-menuicon-nav-guideicon-searchicon-staricon-tag