How to set the left padding of an element with JavaScript?

JavascriptObject Oriented ProgrammingFront End Technology

Use the paddingLeft property in JavaScript to set the left padding. You can try to run the following code to return the left padding of an element with JavaScript −

Example

<!DOCTYPE html>
<html>
   <head>
      <style>
         #box {
            border: 2px solid #FF0000;
            width: 150px;
            height: 70px;
         }
      </style>
   </head>

   <body>
      <div id = "box">This is demo text.</div>
      <br><br>
      <button type = "button" onclick = "display()">Left padding</button>
      <script>
         function display() {
            document.getElementById("box").style.paddingLeft = "100px";
         }
      </script>
   </body>
</html>
raja
Updated on 23-Jun-2020 11:19:22

Advertisements