/

HTML / CSS / JavaScript Tutorial

CSS Property: padding-right

[this page | pdf | back links]

The CSS (CSS1) padding-right property sets the width of the right padding (space) of an element.

 

Valid property values (other than inherit and initial) are:

 

Value

Description

length

Any specified thickness as a CSS length

%

As percentage of width of containing element

 

Default Value:

0

JavaScript syntax:

e.g. object.style.paddingRight="4px"

Inherited:

No

Animatable:

Yes

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
div {border: 2px solid red; width: 100px; background-color: yellow}
span {border: 2px solid green; background-color: aqua;}
.x1 {padding-right: 5px;}
</style>
</head>
<body>
1. Element with default property<br>
<div><span>1</span></div><br><br>
2. Element set using in-file HTML style<br>
<div><span class="x1">2</span></div><br><br>
3. Element set using JavaScript<br>
<div><span id="x2">3</span></div>

<script>
document.getElementById("x2").style.backgroundColor = "aqua";
document.getElementById("x2").style.paddingRight = "5px";
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedCSSPropertyPaddingRight() {
  var x = document.createElement("DIV"); x.style.paddingRight = "5px"; return (window.getComputedStyle(x, null).paddingRight == "5px");
}


NAVIGATION LINKS
Contents | Prev | Next | CSS Properties


Desktop view | Switch to Mobile