HTML | DOM Style paddingLeft Property

paddingLeft : It is used to modify or get the left padding of an element.

  • Difference with marginLeft:
    Both the marginLeft property and the paddingLeft property insert left space to an element. However, the difference is that marginLeft inserts the space around the border, while paddingLeft inserts the space within the border to the left of an element.

Syntax:

  • It returns the paddingLeft property.
    object.style.paddingLeft
  • It sets the paddingLeft Property.
    object.style.paddingLeft = "%|length|initial|inherit"

Return value:It returns the left padding of an element.



Example-1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style paddingLeft Property </title>
    <style>
        #Geek_1 {
            color: green;
            width: 50%;
        }
          
        #Geek_Center {
            width: 400px;
            background: yellow;
        }
    </style>
</head>
  
<body bgcolor="green">
    <center id="Geek_Center">
        <h1 id="Geek_1"
                GeeksForGeeks 
            </h1>
  
        <h2>DOM Style paddingLeft Property </h2>
        <br>
        
        <button type="button" onclick="geeks()">
            Click to change
        </button>
  
        <script>
            function geeks() {
                
                //  Set padding left using 
                //  length unit.
                document.getElementById(
                  "Geek_Center").style.paddingLeft =
                  "50px";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

Before click on button:

After click on the button:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM Style paddingLeft Property </title>
    <style>
        #Geek_1 {
            color: green;
            width: 50%;
        }
          
        #Geek_Center {
            width: 400px;
            background: yellow;
        }
    </style>
</head>
  
<body bgcolor="green">
    <center id="Geek_Center">
        <h1 id="Geek_1"
                GeeksForGeeks 
            </h1>
  
        <h2>DOM Style paddingLeft Property </h2>
        <br>
        <button type="button" onclick="geeks()">
            Click to change
        </button>
  
        <script>
            function geeks() {
                
                //  Set 'left padding'
                //  using %.
                document.getElementById(
                  "Geek_Center").style.paddingLeft =
                  "20%";
            }
        </script>
    </center>
</body>
  
</html>

chevron_right


Output:

Before click on button:

After click on button:

Supported Browsers: The browser supported by DOM Style paddingLeft property are listed below:

  • Google Chrome
  • Internet Explorer
  • Mozilla firefox
  • Safari
  • Opera


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.