CSS Property margin-left

margin-left sets the width of the left margin for an element. Negative values are permitted.


Initial value 0
Inherited No.
Version CSS1
JavaScript syntax object.style.marginLeft="10px"
Applies to All elements.

CSS Syntax

margin-left: length | percentage | auto | inherit 

Property Values

The property values are listed in the following table.

auto Default value. The browser does the calculation.
length Set width in px, cm, etc.
% Set width in percent of the containing element
inherit Inherit the width property from the parent element

Browser compatibility

margin-left Yes Yes Yes Yes Yes


The following code uses the percentage and em to set the left margin.

p {margin-left: 5%;} 
pre {margin-left: 3em;}

        <style rel='stylesheet' type='text/css'>
<!--from   ww w . ja v  a  2  s  .c o  m-->
div {
    width: 100px;
    height: 100px;
    background: mistyrose;
    border: 1px solid pink;
div#topbottom-rightleft {
    margin-top: 15px;
    margin-right: 5px;
    margin-bottom: 15px;
    margin-left: 5px;
        <div id='topbottom-rightleft'></div>

Click to view the demo