Skip to content
Related Articles

Related Articles

HTML | DOM Paragraph align Property
  • Last Updated : 27 Mar, 2020

The HTML DOM Paragraph align property is used to set or return the value of the data 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 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.






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




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

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :