CSS | flex-grow Property

The flex-grow property specifies that how much the item will grow compared to others item inside that container. In other words it is the ability of an item to grow compared to other items present inside the same container.

Note: If the item in the container is not flexible item then flex-grow property will not affect that item.

Syntax:

flex-grow: number

Example: Here we are going to see in a single container there are 5 divs, we will apply the flex-grow on 2nd div and that div will grow compare to other 4 divs. We can apply flex-grow on any document in the same container that div will grow compare to other div’s width, flex-grow property will help that div to grow in comparison to other items in that container.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
<style>
    #main {
            width: 350px;
            height: 100px;
            border: 1px solid black;
            display: -webkit-flex; 
            display: flex;
            color:white;
            text-align:center;
    }
          
    h1 { 
        color:#009900; 
        font-size:42px; 
        margin-left:50px; 
    
      
    h3 { 
        margin-top:-20px; 
        margin-left:50px; 
    
  
    #main div:nth-of-type(1) {flex-grow: 1;}
    #main div:nth-of-type(2) {flex-grow: 5;}
    #main div:nth-of-type(3) {flex-grow: 1;}
    #main div:nth-of-type(4) {flex-grow: 1;}
    #main div:nth-of-type(5) {flex-grow: 1;}
</style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1
    <h3>The flex-grow:number</h3>
      
    <!-- Making 5 divs in main -->
    <div id="main">
        <div style="background-color:#009900;">Sql</div>
        <div style="background-color:#00cc99;">Python</div>
        <div style="background-color:#0066ff;">Java</div>
        <div style="background-color:#66ffff;;">C++</div>
        <div style="background-color:#660066;">C#</div>
    </div>
</body>
</html>                        

chevron_right


Output:

Supported Browser :

  • Google Chrome 29.0
  • Internet Explorer 11.0
  • Mozila Firefox 28.0
  • Safari 9.0
  • Opera 17.0


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.