Easy Tutorial
❮ Prop Date Required Prop Cssstyle Parentrule ❯

Style marginLeft Property


Definition and Usage

The marginLeft property sets or returns the left margin of an element.

Syntax

Set the marginLeft property:

Return the marginLeft property:

Value Description
% Defines the left margin as a percentage of the parent element's width.
length Defines the width of the left margin using units like px, cm, etc.
auto The browser sets the left margin.
inherit The left margin is inherited from the parent element.

Browser Support

All major browsers support the marginLeft property.

Note: IE7 and earlier versions do not support the "inherit" value. IE8 requires !DOCTYPE to be specified for "inherit" to work. IE9 supports "inherit".


Tips and Notes

Both the margin and padding properties insert space around an element. However, the difference is that margin inserts space outside the border, while padding inserts space inside the element's border.


Example

Change the left margin of a div element:


❮ Prop Date Required Prop Cssstyle Parentrule ❯