HTML DOM Style verticalAlign Property


The HTML DOM style verticalAlign property returns and modify the vertical alignment of the content of an HTML element in an HTML document.

Syntax

Following is the syntax −

  • Returning verticalAlign

object.style.verticalAlign
  • Modifying verticalAlign

object.style.verticalAlign = “value”

Values

Here, value can be −

ValueExplanation
initialIt set this property value to its default value.
inheritIt inherits this property value from its parent element.
lengthIn increment or decrement an element by a specific length.
percentage(%)It raises or lower an element in terms of percentage of line-height property.
baselineIt aligns the baseline of an element with the baseline of its parent element.
subIt aligns the element as a subscript.
superIt aligns the element as a superscript.
topIt aligns the top of the element with the top of the tallest element on the line.
text-topIt aligns the top of the element with the top of the parent’s element font.
middleIt aligns the element in the middle of the parent element.
bottomIt aligns the bottom of the element with the lowest element on the line.
text-bottomIt aligns the bottom of the element with the bottom of the parent’s element font.

Example

Let us see an example of HTML DOM style verticalAlign property −

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      background: lightblue;
      height: 100vh;
   }
   table {
      border: 2px solid #fff;
      height: 150px;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem 0;
   }
</style>
</head>
<body>
<h1>DOM Style verticalAlign Property Example</h1>
<table>
<tr>
<td id="myTd">Table Data</td>
</tr>
</table>
<button onclick="add()" class="btn">Set verticalAlign</button>
<script>
   function add() {
      document.querySelector('td').style.verticalAlign = "top";
   }
</script>
</body>
</html>

Output

This will produce the following output −

Click on “Set verticalAlign” button to adjust vertical alignment of text −

Updated on: 01-Jul-2020

16 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements