X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Style paddingTop Property

Style Object Reference Style Object

Example

Set the top padding of a <div> element:

document.getElementById("myDiv").style.paddingTop="50px";

Try it yourself »


Definition and Usage

The paddingTop property sets or returns the top padding of an element.

The padding properties define the space between the element border and the element content.

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

Internet Explorer Firefox Opera Google Chrome Safari

The paddingTop property is supported in all major browsers.


Syntax

Return the paddingTop property:

object.style.paddingTop

Set the paddingTop property:

object.style.paddingTop="%|length|initial|inherit"

Property Values

Value Description
% Defines the top padding in % of the width of the parent element
length Defines the top 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 top padding of an element
CSS Version CSS1


More Examples

Example

Change the top padding of a <div> element back to "normal":

document.getElementById("myDiv").style.paddingTop="0px";

Try it yourself »

Example

Return the top padding of a <div> element:

alert(document.getElementById("myDiv").style.paddingTop);

Try it yourself »

Example

Difference between marginTop and paddingTop:

function changeMargin()
{
document.getElementById("myDiv").style.marginTop="100px";
}
function changePadding()
{
document.getElementById("myDiv2").style.paddingTop="100px";
}

Try it yourself »


Related Pages

CSS tutorial: CSS Padding

CSS reference: padding-top property

HTML DOM reference: padding property


Style Object Reference Style Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook