Open In App

HTML DOM caption align Property

Last Updated : 21 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM caption align Property is used to set or return the value of the align attribute of <caption> element.

Note: This property is not supported by HTML5.

Syntax: 

It returns the caption align property.

captionobject.align;

It sets the caption to align the property.

captionobject.align="left | right | center| Top | Bottom"

Property Values: 

  • left: It sets the left-align to the caption element.
  • center: It sets the center alignment to the caption element. It is the default value.
  • right: It sets the right-align to the caption element. 
  • Top: It sets the top-align caption of the table. 
  • Bottom: It sets the bottom-align caption of the table.

Return Value: It returns a string value that represents the alignment of the caption element. 

Example 1: This example returns the caption align property. 

HTML




<!DOCTYPE html>
<html>
 
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>
 
<body>
    <h1 style="color:green;font-size:35px;">
        GeeksForGeeks
    </h1>
    <h2>DOM Caption align Property</h2>
    <table>
        <caption id="GFG" align="left">
              Students
          </caption>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
    <br>
    <button onclick="myGeeks()">
          Submit
      </button>
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
            let w = document.getElementById("GFG").align;
            document.getElementById("sudo").innerHTML = w;
        }
    </script>
   
</body>
 
</html>


Output:

 

Example 2: This example returns the caption align property. 

html




<!DOCTYPE html>
<html>
 
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
    </style>
</head>
 
<body>
    <h1 style="color:green;font-size:35px;">
        GeeksForGeeks
    </h1>
    <h2>DOM Caption align Property</h2>
    <table>
        <caption id="GFG" align="left">
            Students
        </caption>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
    <br>
    <button onclick="myGeeks()">
          Submit
      </button>
    <p id="sudo"></p>
 
    <script>
        function myGeeks() {
            let w = document.getElementById(
                "GFG").align = "right";
            document.getElementById(
                "sudo").innerHTML = w;
        }
    </script>
   
</body>
 
</html>


Output:

 

Supported Browsers: The browsers supported by HTML DOM caption align Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Apple Safari
  • Opera


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads