CSS Properties

Margin Properties

This property is used to set the margin of specified element.
  • margin-left
  • margin-right
  • margin-top
  • margin-bottom
  • margin
Margin-left

This property is used to set left margin of element. We can set this property to auto or length in the form of %, cm, px etc. It is by default set 0px. When we set auto value browser decide the margin.

Example:

h1 {
margin-left : 40px;
}


Margin-right

This property is used to set right margin of element. We can set this property to auto or length in the form of %, cm, px etc. It is by default set 0px. When we set auto value browser decide the margin.

Example:

h1 {
margin-right : 40px;
}


Margin-top

This property is used to set top margin of element. We can set this property to auto or length in the form of %, cm, px etc. It is by default set 0px. When we set auto value browser decide the margin.

Example:

h1 {
margin-top : 40%;
}


Margin-bottom

This property is used to set bottom margin of element. We can set this property to auto or length in the form of %, cm, px etc. It is by default set 0px. When we set auto value browser decide the margin.

Example:

h1 {
margin-bottom : 40px;
}


Margin

TIts shorthand margin property It declares all margin properties in one single line. We can set this property to auto or length in the form of %, cm, px etc. It is by default set 0px. When we set auto value browser decide the margin.

Example:

h1 {
margin : 40px 20px 30px 40px;
}


Cristle Academy

Compiler