margin

Sets the width of the top, right, bottom, and left margins of the object.

Syntax

{ margin: sMargin }

Possible values

sMargin

String that specifies up to four of the following space-delimited values:

top

Any of the range of margin width values available to the margin-top property.

right

Any of the range of margin width values available to the margin-right property.

bottom

Any of the range of margin width values available to the margin-bottom property.

left

Any of the range of margin width values available to the margin-left property.

The property has a default value of 0 0. It is not inherited.

Remarks

This is a shorthand property that specifies up to four width 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 the top, right/left, and bottom borders, respectively. Negative margins are supported except for top and bottom margins on inline objects.

For inline elements, the top and bottom values are used to compute the border area of a surrounding inline element, if it is present. These values do not contribute to the height of a line.

Margins are always transparent.

Examples

The following example uses the margin property to change the margin of the object. This example uses the IMG object as a selector to set the margin of images to 1 centimeter:

<style>
    img {margin:1cm}
</style>

Standards information

This property is defined in Cascading Style Sheets (CSS), Level 1 (CSS1) Ee371267.xtlink_newWindow(en-us,Expression.40).png.

Applies to

a, abbr, acronym, b, bdo, big, blockquote, body, button, caption, center, cite, code, custom, dd, defaults, del, dfn, div, dl, dt, em, embed, fieldset, font, form, hn, hr, i, iframe, img, input type=button, input type=checkbox, input type=file, input type=image, input type=password, input type=radio, input type=reset, input type=submit, input type=text, ins, li, object, ol, p, q, s, span, sub, table, td, th, tt, u, ul, var, xmp

See also

Concepts

margin-top
margin-right
margin-bottom
margin-left

Send feedback about this topic to Microsoft. © 2011 Microsoft Corporation. All rights reserved.