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

CSS Reference Manual

CSS @rules (RULES)

Comprehensive CSS Properties

CSS left attribute usage and example

The left CSS attribute specifies the offset amount of the left edge of the positioned element relative to the left edge of the reference element box or the browser window.

  • ForAbsolutely positionedElement, the left attribute specifies the distance from the left edge of the element box to the left edge of the containing block.

  • ForRelatively positionedElement, the left attribute specifies the offset amount of the left edge of the element box relative to the left edge of the box itself (that is, the position of the box is specified in the normal flow, and then offset from this position according to these attributes).

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:auto
Applies to:Positioned elements
Inheritance:No
Can be animated:Yes.Please refer to Animation properties.
Version:CSS 2,3
JavaScript syntax:object.style.left="100px"

The syntax of left

The syntax of this attribute is as follows:

left: length | percentage | auto | initial | inherit

The following example demonstrates how to use the left attribute.

  p {
   position: absolute;
   left: 150px;
  }
Test and see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
lengthThe specified offset size, the length value is in px, pt, cm, em, etc., negative values are allowed.
percentageSpecify a percentage offset. The percentage is calculated relative to the width of the element's containing block. Negative percentage values are allowed.
autoThe browser calculates the left edge position. This is the default value.
initialSet this attribute to its default value.
inheritIf specified, the associated elements will adopt the left attribute value of its parent element.

Browser compatibility

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

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 6+

Read more

Please refer to the following tutorials:CSS position,CSS layer.

Related attributes:position,top,right,bottom,z-index.