Name
margin — NN 4 IE 4 CSS 1
Synopsis
Inherited: No
A shortcut attribute that can set the margin widths of up to four edges of an element with one statement. A margin is space that extends beyond the border of an element to provide extra empty space between adjacent or nested elements, especially those that have border attributes set. You may supply one to four space-delimited margin values. The number of values determines which sides receive the assigned margins.
CSS Syntax
margin: marginThickness | auto {1,4}JavaScript Equivalent
margins()
Value
This attribute accepts one, two, three, or four values, depending on
how many and which margins you want to set. Values for
marginThickness can be
lengths, percentages of the next outermost
element size, or the auto constant. Value quantities and positions
are interpreted as follows:
|
Number of Values |
Effect |
|---|---|
|
1 |
All four margin edges set to value |
|
2 |
Top and bottom margins set to the first value, right and left margins set to the second value |
|
3 |
Top margin set to first value, right and left margins set to second value, bottom margin set to third value |
|
4 |
Top, right, bottom, and left margin set, respectively |
Initial Value
0
Example
P.highlight {margin: 10px 20px}Applies To
All elements.
Object Model Reference
- IE
[window.]document.all.elementID.style.margin
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access