The HTML DOM Style flexGrow property is used to set the proportion by which an element accommodates its size inside a flex element. It accepts unitless numeric values.
Following is the syntax for −
Setting the flexGrow property −
object.style.flexGrow = "number|initial|inherit"
Here, number specifies how much the element grows in proportion to other elements and its default value is 0. Initial sets the property value to the default value while inherit sets it to the parent property value.
Let us look at an example for the flexGrow property −
Example
<!DOCTYPE html> <html> <head> <style> #demo { height: 100px; border: 3px groove navy; display: flex; text-align: center; line-height: 90px; } div div { box-shadow: inset 0 0 4px indigo; } #demo div:nth-of-type(even) { flex-grow: 1; background-color: lavender; } #demo div:nth-of-type(odd) { flex-grow: 1; background-color: thistle; } </style> <script> function changeFlexGrow() { for(var i=1;i<6;i+=2) document.getElementsByTagName("div")[i].style.flexGrow="3"; document.getElementById("Sample").innerHTML="The odd div elements are now grown 3x their even counterparts"; } </script> </head> <body> <div id="demo"> <div></div> <div></div> <div>DEMO</div> <div></div> <div></div> </div> <p>Change the above odd div size by clicking the below button</p> <button onclick="changeFlexGrow()">Change Flex Grow</button> <p id="Sample"></p> </body> </html>
Output
On clicking the “Change Flex Grow” button −