/

HTML / CSS / JavaScript Tutorial

CSS Property: align-content

[this page | pdf | back links]

The CSS (CSS3) align-content property modifies the behaviour of the flex-wrap property, aligning flex lines. N.B. If you want to align items on the main x-axis then use the justify-content property.

 

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

 

Value

Description

center

Lines packed towards centre of flex container

flex-end

Lines packed towards end of flex container

flex-start

Lines packed towards start of flex container

space-between

Lines distributed evenly in flex container

space-around

Lines distributed evenly in flex container but with half-size spaces at either end

stretch

(default value). Lines stretch to take up remaining space

 

Default Value:

stretch

JavaScript syntax:

e.g. object.style.alignContent = "center";

Inherited:

No

Animatable:

No

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
.x1 {display: flex; flex-wrap: wrap; width: 80px; height: 60px;
    border: 2px solid red; align-content: space-between}
</style>
</head>
<body>
1. Element with default property<br>
<div style="display: flex; flex-wrap: wrap; width: 100px; height: 60px;
   border: 2px solid red;" >
<div>AAA&nbsp;</div><div>BBB&nbsp;</div>
<div>CCC&nbsp;</div><div>DDD&nbsp;</div>
</div>
<br>
2. Element set using in-file HTML style<br>
<div class="x1">
<div>AAA&nbsp;</div><div>BBB&nbsp;</div>
<div>CCC&nbsp;</div><div>DDD&nbsp;</div>
</div>
<br>
3. Element set using JavaScript<br>
<div id="x2">
<div>AAA&nbsp;</div><div>BBB&nbsp;</div>
<div>CCC&nbsp;</div><div>DDD&nbsp;</div>
</div>
<br>

<script>
document.getElementById("x2").style.display = "flex";
document.getElementById("x2").style.flexWrap = "wrap";
document.getElementById("x2").style.width = "80px";
document.getElementById("x2").style.height = "60px";
document.getElementById("x2").style.border = "2px solid red";
document.getElementById("x2").style.alignContent = "space-between";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile