Set all four margins of a <div> element:
The margin property sets or returns the margins of an element.
This property can take from one to four values:
Both the margin property and the padding property insert space around an element. However, the difference is that margin inserts the space around the border, while padding inserts the space within the border of an element.
The margin property is supported in all major browsers.
Return the margin property:
Set the margin property:
Value | Description |
---|---|
% | Defines the margins in % of the width of the parent element |
length | Defines the margins in length units |
auto | The browser sets the margins (all four margins will be equal) |
initial | Sets this property to its default value. Read about initial |
inherit | Inherits this property from its parent element. Read about inherit |
Default Value: | 0 |
---|---|
Return Value: | A String, representing the margins of an element |
CSS Version | CSS1 |
Change all four margins of a <div> element to "25px":
Return the margins of a <div> element:
Difference between the margin property and the padding property:
CSS tutorial: CSS Margin
CSS reference: margin property