CSS Margins

❮ Previous Home Next ❯

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

Example

.example {
  margin: 100px;
}



If the margin property has four values:

margin: 40px 10px 5px 40px;

Example

p {
  margin: 40px 10px 5px 40px;
}



If the margin property has three values:

margin: 10px 20px 30px;

Example

p {
  margin: 10px 20px 30px;
}






If the margin property has two values:

margin: 20px 30px;

Example

p {
  margin: 20px 30px;
}



If the margin property has one value:

margin: 1px;

Example

p {
  margin: 40px;
}



All CSS Margin Properties

Property Description
margin Sets a consistent margin on all four sides of the affected element.
margin-bottom Sets an element’s bottom margin.
margin-left Sets an element’s left margin.
margin-right Sets an element’s right margin.
margin-top Sets an element’s top margin.



❮ Previous Home Next ❯