HTML | DOM Div align Property

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

Syntax:

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

Property Values:

  • left: It sets the left-align to horizontal line.
  • center: It sets the center-align to horizontal line. It is the default value.
  • right: It sets the right-align to horizontal line.

Return Values: It returns a string value which represents the alignment of the Div element.

Example 1: This example returns the Div align property.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                     

chevron_right


Output:
Before Clicking On Button:

After Clicking On Button:

Example 2: This example sets the Div align property.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.