CSS | flex-shrink Property

24 Aug, 2021
The flex-shrink property specifies how much the item will shrink compared to others item inside that container. It defines the ability of an element to shrink in compared to the other elements which are placed inside the same container.
Note: If the item in the container is not flexible item then flex-shrink property will not affect that item.
Syntax:  
flex-shrink: number| initial| inherit;
Default Value: 
1 
Property values:  
number: A number that defines how the item will shrink compare to other flexible items.
initial: It sets the value to its default value.
inherit: It inherit the property from its parent elements.
Example: Here we are going to see in a single container there are 5 div, we will apply the flex-shrink on 2nd div and that div will shrink compared to other 4 div’s. We can apply flex-shrink on any document in the same container and that div will shrink compared to other div’s width, flex-shrink will shrink that div compared to other items in that container. 
HTML
<!DOCTYPE html><html> <head>    <title>        CSS | flex-shrink Property    </title>    <style>        #main {            width: 450px;            height: 200px;            border: 1px solid black;            display: -webkit-flex;            display: flex;            color: white;        }                 h1 {            color: #009900;            font-size: 42px;            margin-left: 50px;        }                 h3 {            margin-top: -20px;            margin-left: 50px;        }                 #main div {            flex-grow: 1;            flex-shrink: 1;            flex-basis: 100px;        }                 <!-- shrinking the 2nd div compare to others -->        #main div:nth-of-type(2) {            flex-shrink: 4;        }    </style></head> <body>    <h1>GeeksforGeeks</h1>     <h3>The flex-shrink:number</h3>     <!-- Making 5 divs in main -->    <div id="main">        <div style="background-color:#009900;">              <p>                A number specifying how much the item              will shrink relative to the rest of the              flexible items.            </p>          </div>         <div style="background-color:#00cc99;">              <p> Default value is 1</p>          </div>         <div style="background-color:#0066ff;">              <p>              Initial Sets this property to              its default value            </p>          </div>         <div style="background-color:#66ffff;;"></div>         <div style="background-color:#660066;">              <p>              Inherits this property from              its parent element            </p>          </div>    </div></body> </html>            
Output:  
Supported Browser: The browser supported by CSS | flex-shrink Property are listed below:  
Google Chrome 29.0
Internet Explorer 11.0
Mozilla Firefox 28.0
Opera 17.0
Safari 9.0
 
arorakashish0911
ManasChhabra2
CSS-Properties
Picked
Technical Scripter 2018
CSS
HTML
Technical Scripter
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to update Node.js and NPM to next version ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to create footer to stay at the bottom of a Web page?
CSS to put icon inside an input element in a form
How to update Node.js and NPM to next version ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
REST API (Introduction)
Hide or show elements in HTML using display property