Margin
Margin
The Margin
property specifies the margin area on all four sides of an element. It is a shorthand for margin-top
, margin-right
, margin-bottom
, and margin-left
. When one value is specified, it applies the same margin to all four sides.
Examples
Single Margin Value
Using the shorthand property to set the margin for all four sides of a <p>
element to 40 pixels.
p {
margin: 40px;
}
Multiple Margin Values
Setting multiple margin values for the four sides of a <p>
element.
- The top margin is 10px.
- The right margin is 5px.
- The bottom margin is 15px.
- The left margin is 20px.
p {
margin: 10px 5px 15px 20px;
}
Syntax
margin: value;
Tips
- Margins create extra space around an element. In contrast, padding creates extra space inside an element. The default margin value is 0.
- You can specify the margin for the individual sides of an element using the CSS
margin-top
,margin-right
,margin-bottom
, andmargin-left
properties, respectively.
Additional Information
For more information, see http://www.w3schools.com/cssref/pr_margin.asp.
Found a bug in the documentation? Let us know at support@code.org.