Skip to content
Related Articles

Related Articles

Improve Article

HTML | DOM Paragraph align Property

  • Last Updated : 10 May, 2021

The HTML DOM Paragraph align property is used to set or return the value of the align attribute of a <p> element. 
Syntax: 
 

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

Property Values: 
 

  • left: It sets the left-align to paragraph.
  • center: It sets the center-align to paragraph. 
  • right: It sets the right-align to paragraph.

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

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM paragraph align property
    </title>
</head>
 
<body style="text-align:center;">
  
    <h1 style = "color:green;" >
        GeeksForGeeks
    </h1>
     
    <h2>DOM paragraph align Property </h2>
 
    <button onclick="Geeks()">
        Click Here
    </button>
 
    <p id="s" align="left">
        A computer science portal for geeks.
    </p>
  
     
    <p id="geeks"></p>
  
     
    <script>
        function Geeks() {
            var txt = document.getElementById("s").align;
         
            document.getElementById(
                    "geeks").innerHTML=txt;
        }
    </script>
</body>
 
</html>

Output: 
Before Clicking on Button: 
 



After Clicking on Button: 
 

Example 2: This example sets the paragraph align property. 
 

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        HTML DOM paragraph align property
    </title>
</head>
 
<body style="text-align:center;">
     
    <h1 style = "color:green;" >
        GeeksForGeeks
    </h1>
     
    <h2>DOM paragraph align Property</h2>
  
    <button onclick="Geeks()">
        Click Here
    </button>
  
    <p id="s" align="left">
        A computer science portal for geeks.
    </p>
  
     
    <p id="geeks"></p>
  
     
    <script>
        function Geeks() {
            var txt = document.getElementById(
                        "s").align = "right";
                         
            document.getElementById(
                    "geeks").innerHTML = txt;
        }
    </script>
</body>
 
</html>

Output: 
Before Clicking on Button: 
 

After Clicking on Button: 
 

Supported Browsers: The browsers supported by DOM Paragraph 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 :