Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Div align Property

  • Last Updated : 10 May, 2021

The HTML | DOM Div align Property is used to set or return the value of the align attribute of a <div> element. 
Syntax: 
 

  • It returns the div align property. 
     
div object.align;
  • It sets the div align property. 
     
div object.align="left | right | center"

Property Values: 
 

  • left: It sets the left-align to <div> element.
  • center: It sets the center-align to div element. It is the default value.
  • right: It sets the right-align to <div> element.

Return Values: It returns a string value which represents the alignment of the Div element. 
Example 1: This example returns the Div align property. 
 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        HTML DOM Div align Property
    </title>
</head>
 
<body style = "text-align:center;">
 
    <h1 style = "color:green;" >
        GeeksForGeeks
    </h1>
         
    <div id="div_obj">DOM Div align Property</div>
    <br>
     
    <button onclick = "Geeks()">
        Click Here!
    </button>
         
    <br><br>
         
    <div id = "GFG" align="left">
        A portal for geeks.
    </div>
    <p id="geeks"></p>
 
    <!-- script to access div object -->
    <script>
        function Geeks() {
            var dv = document.getElementById("GFG").align;
            document.getElementById("geeks").innerHTML = dv;
        }
    </script>
</body>
 
</html>                    

Output: 
Before Clicking On Button: 
 



After Clicking On Button: 
 

Example 2: This example sets the Div align property. 
 

html




<!DOCTYPE html>
<html>
     
<head>
    <title>
        HTML DOM Div align Property
    </title>
</head>
 
<body style = "text-align:center;">
 
    <h1 style = "color:green;" >
        GeeksForGeeks
    </h1>
         
    <div id="div_obj">DOM Div align Property</div>
    <br>
     
    <button onclick = "Geeks()">
        Click Here!
    </button>
         
    <br><br>
         
    <div id = "GFG" align="left">
        A portal for geeks.
    </div>
    <p id="geeks"></p>
 
    <!-- script to access div object -->
    <script>
        function Geeks() {
            var dv = document.getElementById("GFG").align = "right";
            document.getElementById("geeks").innerHTML = dv;
        }
    </script>
</body>
 
</html>

Output: 
Before Clicking On Button: 
 

After Clicking On Button: 
 

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

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

 

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :