CSS flex-shrink

The CSS flex-shrink property is used to shrink flex items relatively, in same flex container. For example:

HTML with CSS Code
<!DOCTYPE html>
<html>
<head>
   <style>
      .container{width: 380px; display: flex; background-color: brown;}
      .container > div{flex-basis: 120px; padding: 12px; border: 1px solid coral; color: wheat;}
      #secondiv{flex-shrink: 4;}
   </style>
</head>
<body>

   <div class="container">
      <div>A</div>
      <div id="secondiv">B</div>
      <div>C</div>
      <div>D</div>
   </div>
   
</body>
</html>
Output
A
B
C
D

CSS flex-shrink Syntax

The syntax of flex-shrink property in CSS, is:

flex-shrink: x;

The value of x should be any of the following:

CSS Online Test


« Previous Tutorial Next Tutorial »