Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Style padding Property

Style padding Property

Style Object Reference The Style object


Definition and Usage

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

This property can use from 1 to 4 values:

Syntax

Set the padding property:

Object.style.padding="

%

|

length

|inherit"

Return the padding property:

Object.style.padding

Value Description
% Defines a padding as a percentage of the parent element's width.
length Defines the width of the padding using units such as px, cm, etc.
inherit The padding is inherited from the parent element.

Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the padding property.

**Note:** IE7 and earlier versions do not support the "inherit" value. IE8 supports "inherit" only if a !DOCTYPE is specified. IE9 supports "inherit".


Tips and Notes

Both the margin property and the padding property insert space around an element. However, they differ: margin inserts space outside the border, while padding inserts space inside the border.


Example

Example

Change the padding of a div element:

Runoob Tutorial(runoob.com)
This is some text.



This is some text.

Try it »


Style Object Reference The Style object