/

HTML / CSS / JavaScript Tutorial

CSS Property: vertical-align

[this page | pdf | back links]

The CSS (CSS1) vertical-align property indicates the vertical alignment of an element.

 

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

 

Value

Description

length

Raises (positive) or lowers (negative) element by a CSS length

%

Raises of lowers element by percentage of line-height property

baseline

(default value). Baseline of element aligned with baseline of parent

bottom

Bottom of element aligned with bottom of lowest element on line

middle

Element is placed vertically in middle of parent

sub

Aligns element as if it was a subscript

super

Aligns element as if it was a superscript

text-bottom

Bottom of element aligned with bottom of parent text

text-top

Top of element aligned with top of parent text

top

Top of element aligned with top of highest element on line

 

Default Value:

baseline

JavaScript syntax:

e.g. object.style.verticalAlign="sub"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {border: 2px solid red; width: 100px; height: 40px; background-color: yellow}
.x1 {vertical-align: super;}
</style>
</head>
<body>
1. Element with default property<br>
<div>a<span>1</span></div><br>
2. Property set using HTML<br>
<div>a<span class="x1">2</span></div><br>
3. Property set using JavaScript<br>
<div>a<span id="x2">3</span></div>

<script>
document.getElementById("x2").style.verticalAlign = "super";
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile