Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

How to use Margin Property in CSS?

CSS

margin

Its 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. 

Ex: –

img { margin: 10px 20px 30px 40px;}

Margin Property

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. 

Ex: –

img { margin-left: 20%; }
h1 { margin-left: 40px; }
p { margin-left: auto; }

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. 

Ex: –

img { margin-right: 20%; }
h1 { margin-right: 40px; }
p { margin-right: auto; }

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. 

Ex: –

img { margin-top: 20%; }
h1 { margin-top: 40px; }
p { margin-top: auto; }

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. 

Ex: –

img { margin-bottom: 20%; }
h1 { margin-bottom: 40px; }
p { margin-bottom: auto; }

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x