CSS margin Property

❮ Previous Reference Next ❯

Example

.example {
  margin: 100px;
}





Hello World!

Meaning

The margin property sets a consistent margin on all four sides of the affected element.

If the margin property has four values:

margin: 1px 2px 3px 4px;

If the margin property has three values:

margin: 1px 2px 3px;

If the margin property has two values:

margin: 1px 2px;

If the margin property has one value:

margin: 1px;

Default value:0
Inherited:No
Animatable:Yes
Version:CSS1
JavaScript syntax:
object.style.margin="length|auto|%|initial|inherit|revert|revert-layer|unset";



Standard Syntax

margin: length|auto|%|initial|inherit|revert|revert-layer|unset;



Browser Support

The numbers in the table specify the first browser version that fully supports the property.




Status







Property Values

The following table describes the values of this property.

Value Description
length Specifies a margin in px, pt, cm, etc. Default value is 0. Negative values are allowed.
auto The browser calculates a margin.
%(percentage) Specifies a margin in percent of the width of the containing element.
initial Sets this property to its default value.
inherit If specified, the associated element takes the computed value of its parent element animation-delay property.
revert Reverts the cascaded value of the property from its current value to the value the property
revert-layer Rollback styles to the ones specified in previous cascade layers.
unset Resets a property to its inherited value if the property naturally inherits from its parent, and to its initial value if not.



Default CSS Property Values

selectors {
  margin: 0;
}
❮ Previous Reference Next ❯