English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive List of CSS Properties

CSS margin-Usage and examples of left attribute

margin-The left CSS attribute sets the left margin of the element. However, in many cases, likemarginSuch a shorthand CSS attribute is more convenient and preferable to use.

The following table provides usage instructions and version history of this attribute, as well as the syntax of using this attribute in JavaScript scripts.

Default value:0
Applies to:All elements, but not table displayType (table-caption table inline-elements except for table) outside. . It also applies to ::first-letter.
Inheritance:No
Animaatable:Yes.Please refer to Animation properties.
Version:CSS 1,2,3
JavaScript syntax:object.style.marginLeft="20px"

margin-The syntax of left

The syntax of this attribute is as follows:

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

The following examples demonstrate how to use margin-left attribute.

  h1 {
   margin-left: 25px;
  }
  p {
   margin-left: 50px;
  }
Test and see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
lengthLength value, in units of px, pt, cm, em, etc. Negative values are allowed.
percentagePercentage. The percentage is calculated relative to the width of the element's containing block.
autoThe browser will calculate the margin of the specified element.
initialSet this attribute to its default value.
inheritIf specified, the associated element uses its parent element's margin-The value of the left attribute.

Browser compatibility

margin-The compatibility of the left attribute of the browser, the numbers in the following table represent the minimum version number of the browser that supports this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 3+

  • Apple Safari 1+

  • Opera 4+

Further reading

Please refer to the following tutorials:CSS Margin,CSS Box Model.

Related properties:margin,margin-top,margin-right,margin-bottom.