CSS Intro

CSS Intro Quiz

CSS Intro Exercise

CSS Basic

CSS Basic Quiz

CSS Basic Exercise

CSS Advance

CSS Advance Quiz

CSS Advance Exercise


CSS3 Quiz

CSS3 Exercise

CSS Properties

CSS Functions

CSS Selectors

CSS margin Property

CSS margin Property



The margin property is used to specify the margins for an element. It is a shorthand property for:-

  • margin-top
  • margin-right
  • margin-bottom
  • margin-left


For Your Information:-


  1. If the margin property has four values then the margin is applied from the top, right, bottom, and left.
  2. If the margin property has three values then the margin is applied to the top, right and left, and bottom.
  3. If the margin property has two values then the margin is applied to the top and bottom, and right and left.
  4. If the margin property has one value then it is applied to all four sides.


We can use negative values in it.


Default Value:-


Its default value is 0.




Its syntax is:- margin: length | auto | initial | inherit;


Further Explanation:-


Value Description
length Specifies a margin in px, pt, cm, etc.
% Specifies a margin in percent of the width of the containing element
auto The browser calculates a margin
initial Sets this property to its default value.
inherit Inherits this property from its parent element.

Code Explanation

All Tutorials related to CSS Properties

All Sections related to CSS