HTML DOM Style paddingRight Property


The HTML DOM Style paddingRight property return and add right padding to an HTML element.

Syntax

Following is the syntax −

1. Returning paddingRight

object.style.paddingRight

2. Adding paddingRight

object.style.paddingRight=”value”

Here, “value” can be the following −

ValueDetails
lengthIt defines value padding in length unit.
initialIt defines padding to its default value.
inheritIn this padding gets inherited from its parent element.
percentage(%)It defines padding in percentage of the width of the parent element.

Let us see an example of HTML DOM Style paddingRight property−

Example

 Live Demo

<!DOCTYPE html>
<html>
<head>
<style>
   .outer-box {
      background-color: #db133a;
      width: 300px;
      height: 300px;
      margin: 1rem auto;
   }
   .inner-box {
      background-color: #C3C3E6;
      width: 100%;
      height: 150px;
   }
</style>
</head>
<body>
<h1>HTML DOM Style paddingRight Property Demo</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.paddingRight = '20px';
   }
</script>
</body>
</html>

Output

Click on “Add Padding” button to add padding inside red box.

Updated on: 27-Sep-2019

64 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements