Export (0) Print
Expand All

padding property

Sets or retrieves the amount of space to insert between the object and its margin or, if there is a border, between the object and its border.

CSS 2.1, Section 5.5.10Internet Explorer 9

 

Syntax

padding: <length> | <percentage>

Property values

length

Floating-point number, followed by an absolute units designator (cm, mm, in, pt, or pc) or a relative units designator (em, ex, or px). For more information about the supported length units, see CSS Values and Units Reference.

percentage

Integer, followed by a %. The value is a percentage of the width of the parent object.

CSS information

Applies ToAll elements
Mediavisual
Inheritedno
Initial Value(see individual properties)

Standards information

Remarks

This is a composite property that specifies up to four padding values, in the following order: top, right, bottom, left. If one width value is specified, it is used for all four sides. If two width values are specified, the first is used for the top and bottom borders, and the second is used for left and right borders. If three width values are specified, they are used for top, right/left, and bottom borders, respectively. Negative values are not allowed.

The below illustration shows the content, padding, border, and margin areas of a basic box. The red labels illustrate the edges of each of these areas.

An illustration of the basic box model

As of Microsoft Internet Explorer 5.5, this property applies to inline elements. With earlier versions of Windows Internet Explorer, inline elements must have an absolute position or layout to use this property. Element layout is set by providing a value for the height property or the width property.

Examples

In the following example, a div element contains text and specifies width, border, and padding values.



<div id="padding">
   Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>

In the CSS below, the first padding value sets padding-top to 5 pixels, the second value sets padding-right to 10 pixels, the third value sets padding-bottom to 15 pixels, and the fourth value sets padding-left to 20 pixels.



#padding {
   width: 200px;
   border: .5em solid #BBBBBB;
   padding: 5px 10px 15px 20px;
}

The following image shows the result.

An HTML element with padding applied to all sides

See also

CSSStyleDeclaration
currentStyle
defaults
runtimeStyle
style
CSS Enhancements in Internet Explorer 6

 

 

Show:
© 2014 Microsoft