
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM paddingLeft Property
The HTML DOM paddingLeft property returns and add left padding to an HTML element.
Syntax
Following is the syntax −
1. Returning left padding
object.style.paddingLeft
2. Adding left padding
object.style.paddingLeft=”value”
Values
Here, “value” can be the following −
Value | Details |
---|---|
length | It defines value padding in length unit. |
initial | It defines padding to its default value. |
inherit | In this padding gets inherited from its parent element. |
percentage(%) | It defines padding in percentage of the width of parent element. |
Example
Let us see an example of paddingLeft property −
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>HTML DOM paddingLeft property</title> <style> .outer-box{ background-color:#db133a; width:300px; height:300px; margin:1rem auto; } .inner-box{ background-color:#C3C3E6; width:150px; height:150px; } </style> </head> <body> <h1>paddingLeft Property Example&t;/h1> <div class="outer-box"> <div class="inner-box"> </div> </div> <button type="button" onClick='addPadding()'>Add Padding</button> <script> function addPadding(){ var outerBox=document.querySelector('.outer-box') outerBox.style.paddingLeft='20px'; console.log(outerBox.style.paddingLeft); } </script> </body> </html>
Output
This will produce the following output −
Click on “Add Padding” button to add padding inside red box.
The above code will also display the following on Console −
- Related Articles
- HTML DOM Style paddingLeft Property
- HTML DOM tagName Property
- HTML DOM name Property
- HTML DOM nextElementSibling Property
- HTML DOM nextSibling Property
- HTML DOM nodeName Property
- HTML DOM nodeType Property
- HTML DOM nodeValue Property
- HTML DOM offsetHeight Property
- HTML DOM offsetLeft Property
- HTML DOM offsetParent Property
- HTML DOM offsetTop Property
- HTML DOM offsetWidth Property
- HTML DOM textContent Property
- HTML DOM title Property

Advertisements