/

HTML / CSS / JavaScript Tutorial

CSS Property: flex-grow

[this page | pdf | back links]

The CSS (CSS3) flex-grow property indicates how much an element will grow relative to the rest of the flexible items in a container. If an element is not a flexible element then this property has no effect.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

number

Specifies how much an item will grow relative to rest of flexible items

 

Default Value:

0

JavaScript syntax:

e.g. object.style.flexGrow="4"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {border: 1px solid black;}
.x1 {flex-grow: 1;}
.x2 {flex-grow: 5;}
</style>
</head>
<body>
1. Element with default property<br>
<div style="display: flex; width: 200px; border: 2px solid red;">
<div>A</div><div>B</div>
</div>
<br>
2. Element set using in-file HTML style<br>
<div style="display: flex; width: 200px; border: 2px solid red;">
<div  class="x1">A</div><div class="x2">B</div>
</div>
<br>
3. Element set using JavaScript<br>
<div style="display: flex; width: 200px; border: 2px solid red;">
<div id="x3">A</div><div id="x4">B</div>
</div>
<br>

<script>
document.getElementById("x3").style.flexGrow = "1";
document.getElementById("x4").style.flexGrow = "5";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyFlexGrow() {
  var x = document.createElement("DIV"); x.style.flexGrow = "10"; return (window.getComputedStyle(x, null).flexGrow == "10");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile