Defines the widths (in pixels, points, or a percentage) for the margins for the element.
Platform Support
IE | Netscape | Mozilla | Opera | Safari | 4.0+ | 4.0+ | 1.0+ | 4.0+ | 1.0+ |
---|
Usage
[top] [right] [bottom] [left]
Example
To specify a margin that is 10px wide on the top and left and 5px wide on the bottom and right, use the following syntax: body {margin: 10px 5px 5px 10px;}
.
Remarks
Use the margin
property as a shortcut to typing out all of the individual margin
properties separately. You can specify any valid value for a margin
property as part of margin
.
You can specify up to four different widths for the margin of an element.
- For a margin that is the same on all four sides, specify a single value.
- For a margin that is different on the top/bottom and left/right sides, specify two values with the top/bottom value first.
- For a margin that is different on the top, left/right, and bottom sides, specify three values with the top value first, followed by the left/right and then bottom values.
- For a margin with four different widths, specify four values in the order of top, right, bottom, and left.
Availability
W3C CSS2