Skip to content
Related Articles

Related Articles

HTML | DOM Paragraph align Property

Improve Article
Save Article
  • Last Updated : 25 May, 2022
Improve Article
Save Article

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

Note: This property is not supported by HTML5

Syntax: 

  • It returns the paragraph align property.
Pobject.align;
  • It sets the paragraph align property.
Pobject.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 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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!