Open In App

CSS margin-left Property

The margin-left property in CSS is used to set the width of the margin on the left of the desired element. Negative values of this property are allowed.

Syntax:



margin-left: length|auto|initial|inherit;

Default Value : Its default value is 0.

Property values:



margin-left: 15px;




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <p style = "margin-left:15px; border-style:solid ; 
                  border-color:black;">
         This paragraph has 15px margin .
      </p>
   </body>
</html>




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <p style = "margin-left:20%; border-style:solid ; 
                  border-color:black;">
         This paragraph has 20% margin .
      </p>
   </body>
</html>

margin-left: auto;




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <p style = "margin-left:auto; border-style:solid ; 
                  border-color:black;">
         This paragraph has auto margin .
      </p>
   </body>
</html>

margin-left: initial;




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <p style = "margin-left:initial; border-style:solid ; 
                  border-color:black;">
         This paragraph has initial margin .
      </p>
   </body>
</html>

margin-left: inherit; 




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <div style="margin-left:50px;">
      <p style = "margin-left:inherit; border-style:solid ; 
                  border-color:black;">
         This paragraph has auto margin .
      </p>
      </div>
   </body>
</html>




<html>
   <head>
      <title>
         CSS | margin-left Property
      </title>
   </head>
     
   <body>
      <p style = "margin-left:auto; border-style:solid ; 
                  border-color:black;">
         This paragraph has auto margin .
      </p>
        
      <p style = "margin-left:10px; border-style:solid ; 
                  border-color:black;">
         This paragraph has 10px margin.
      </p>
      <br>
        
      <p style = "margin-left:5%;border-style:solid; 
                  border-color: black;">
         This paragraph has 5% margin.
      </p>
      <br>
        
      <p style = "margin-left:15px; border-style:solid;
                  border-color: black;">
         This text has an margin of 15px.
      </p>
      <br><br>   
  
      <p style = "margin-left:initial;border-style:solid;
                  border-color: black;">
         This text has a margin of default
         typeset by initial
      </p>   
   </body>
</html

Supported Browsers: The browser supported by margin-left Property are listed below:


Article Tags :