Open In App

HTML | DOM Style padding Property

The Style padding property is used for setting or returning the padding of an element. The Style padding property can be used in 4 different ways :

Syntax:



object.style.padding
object.style.padding = "%|length|initial|inherit"

Return Values: It returns a string value, which represents the padding of an element.

Property values:



Below program illustrates the Style padding property : 

Example 1: Setting the padding{30px} for a <div> element: 




<!DOCTYPE html>
<html>
 
<head>
    <title>Style padding Property in HTML</title>
    <style>
        #samplediv {
            border: 1px solid green;
        }
         
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Style padding Property</h2>
    <br>
 
    <div id="samplediv">Geeksforgeeks</div>
 
    <p>For setting the padding,
      double click the "Set Padding" button: </p>
    <br>
 
    <button ondblclick="padding()">
        Set Padding
    </button>
 
    <script>
        function padding() {
            document.getElementById("samplediv")
                .style.padding = "30px";
        }
    </script>
 
</body>
 
</html>      

Output:

Example 2: Setting the padding{100px 50px} for a <div> element: 




<!DOCTYPE html>
<html>
 
<head>
    <title>Style padding Property in HTML</title>
    <style>
        #samplediv {
            border: 1px solid green;
        }
         
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Style padding Property</h2>
    <br>
 
    <div id="samplediv">Geeksforgeeks</div>
 
    <p>For setting the padding,
      double click the "Set Padding" button: </p>
    <br>
 
    <button ondblclick="padding()">Set Padding </button>
 
    <script>
        function padding() {
            document.getElementById("samplediv")
                .style.padding = "100px 50px";
        }
    </script>
 
</body>
 
</html>        

Output:

Example 3: Setting the padding{10px 20px 50px} for a <div> element: 




<!DOCTYPE html>
<html>
 
<head>
    <title>Style padding Property in HTML</title>
    <style>
        #samplediv {
            border: 1px solid green;
        }
         
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Style padding Property</h2>
    <br>
 
    <div id="samplediv">Geeksforgeeks</div>
 
    <p>For setting the padding,
      double click the "Set Padding" button: </p>
    <br>
 
    <button ondblclick="padding()">
        Set Padding
    </button>
 
    <script>
        function padding() {
            document.getElementById("samplediv")
                .style.padding = "10px 20px 50px";
        }
    </script>
 
</body>
 
</html>    

Output:




<!DOCTYPE html>
<html>
 
<head>
    <title>Style padding Property in HTML</title>
    <style>
        #samplediv {
            border: 1px solid green;
        }
         
        h1 {
            color: green;
        }
         
        h2 {
            font-family: Impact;
        }
         
        body {
            text-align: center;
        }
    </style>
</head>
 
<body>
 
    <h1>GeeksforGeeks</h1>
    <h2>Style padding Property</h2>
    <br>
 
    <div id="samplediv">Geeksforgeeks</div>
 
    <p>For setting the padding,
      double click the "Set Padding" button: </p>
    <br>
 
    <button ondblclick="padding()">
        Set Padding
    </button>
 
    <script>
        function padding() {
            document.getElementById("samplediv")
                .style.padding = "100px 10px 20px 40px";
        }
    </script>
 
</body>
 
</html>       

Supported Browsers:


Article Tags :