Style paddingRight Property
Example
Set the right padding of a <div> element:
document.getElementById("myDIV").style.paddingRight = "50px";
Try it Yourself »
Definition and Usage
The paddingRight property sets or returns the right padding of an element.
Both the margin property and the padding property insert space around an element. However, the difference is that margin inserts the space around the border, while padding inserts the space within the border of an element.
Browser Support
The paddingRight property is supported in all major browsers.
Syntax
Return the paddingRight property:
object.style.paddingRight
Set the paddingRight property:
object.style.paddingRight="%|length|initial|inherit"
Property Values
Value | Description |
---|---|
% | Defines the right padding in % of the width of the parent element |
length | Defines the right padding in length units |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Technical Details
Default Value: | 0 |
---|---|
Return Value: | A String, representing the right padding of an element |
CSS Version | CSS1 |
More Examples
Example
Change the right padding of a <div> element back to "normal":
document.getElementById("myDIV").style.paddingRight = "0px";
Try it Yourself »
Example
Return the right padding of a <div> element:
alert(document.getElementById("myDIV").style.paddingRight);
Try it Yourself »
Example
Difference between marginRight and paddingRight:
function changeMargin() {
document.getElementById("myDIV").style.marginRight = "200px";
}
function changePadding() {
document.getElementById("myDIV2").style.paddingRight = "200px";
}
Try it Yourself »
Related Pages
CSS tutorial: CSS Padding
CSS reference: padding-right property
HTML DOM reference: padding property
Style Object