CSS | flex-grow Property - GeeksforGeeks

24 Aug, 2021
The flex-grow property specifies 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 the flex-grow property will not affect that item.
Syntax:  
flex-grow: number| initial| inherit;
Default Value: 
0
Property values:  
number: A number that defines how the item will grow compare to other flexible items.
initial: It sets the value to it’s default value.
inherit: It inherit the property from it’s parent elements.
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 compared to other div’s width, the flex-grow property will help that div to grow in comparison to other items in that container.
HTML
<!DOCTYPE html><html> <head>    <title>        CSS | flex-grow Property    </title>    <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>       
Output:  
Supported Browser: The browser supported by CSS | flex-grow Property are listed below:  
Google Chrome 29.0
Internet Explorer 11.0
Mozilla Firefox 28.0
Opera 17.0
Safari 9.0
 
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
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.
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?
How to update Node.js and NPM to next version ?
CSS to put icon inside an input element in a form
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to set the default value for an HTML <select> element ?
How to update Node.js and NPM to next version ?
How to set input type date in dd-mm-yyyy format using HTML ?