/

HTML / CSS / JavaScript Tutorial

CSS Property: align-items

[this page | pdf | back links]

The CSS (CSS3) align-items property specifies the default alignment for items inside a flexible container. Use the align-self property to override the property for any individual item.

 

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

 

Value

Description

baseline

Items positioned at baseline of container

center

Items positioned at centre of container

flex-end

Items positioned at end of container

flex-start

Items positioned at start of container

stretch

(default value). Items stretched to fit container

 

Default Value:

stretch

JavaScript syntax:

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

Inherited:

No

Animatable:

No

 

EXAMPLE:


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

<script>
document.getElementById("x2").style.display = "flex";
document.getElementById("x2").style.width = "200px";
document.getElementById("x2").style.height = "60px";
document.getElementById("x2").style.border = "2px solid red";
document.getElementById("x2").style.alignItems = "flex-end"
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile