HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Set the padding of a <div> element
The padding property sets or returns the padding of an element.
This property can take from one to four values:
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.
Property | |||||
---|---|---|---|---|---|
padding | Yes | Yes | Yes | Yes | Yes |
Return the padding property:
Set the padding property:
Value | Description |
---|---|
% | Defines the padding in % of the width of the parent element |
length | Defines the 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 |
Default Value: | 0 |
---|---|
Return Value: | A String, representing the padding of an element |
CSS Version | CSS1 |
Change the padding of all four sides of a <div> element to "25px":
document.getElementById("myDiv").style.padding = "25px";
Return the padding of a <div> element:
alert(document.getElementById("myDiv").style.padding);
Difference between the margin property and the padding property:
function changeMargin() {
document.getElementById("myDiv").style.margin = "100px";
}
function changePadding() {
document.getElementById("myDiv2").style.padding = "100px";
}
CSS tutorial: CSS Padding
CSS reference: padding property