left property
Sets or retrieves the position of the object relative to the left edge of the next positioned object in the document hierarchy.
![]() |
Syntax
left:
<length>
|
<percentage>
| auto
Property values
auto-
Default. Default position, according to the regular HTML layout of the page.
- length
-
Floating-point number, followed by an absolute units designator (
cm,mm,in,pt, orpc) or a relative units designator (em,ex, orpx). For more information about the supported length units, see CSS Values and Units Reference. - percentage
-
Integer, followed by a percent sign (%). The value is a percentage of the width of the parent object.
CSS information
| Applies To | All elements |
|---|---|
| Media | visual |
| Inherited | no |
| Initial Value |
Standards information
- CSS 2.1, Section 9.3.2
Remarks
You should use the left attribute only when the position attribute is set; otherwise, the value of the left attribute is ignored.
Because the value of the left property is a string, you cannot use the property in script to calculate the position of the object in the document; instead, you should use the pixelLeft property or the posLeft property.
Because the value of the left property is a string, you cannot use the property to calculate the position of the object in the document.
Because the value of the left property is a string, you cannot use the property in script to calculate the position of the object in the document; instead, you should use the pixelLeft property or the posLeft property.
For more information about how to access the dimension and location of objects on the page through the Dynamic HTML (DHTML) Document Object Model (DOM), see Measuring Element Dimension and Location with CSSOM in Internet Explorer 9.
Examples
The following examples use the left attribute and the left property to change the position of the object.
This example uses an inline style sheet to set the position of an image 100 pixels to the right of the parent object's left edge.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/left_h.htm
<DIV STYLE="position:absolute;left:100px"> <IMG SRC="cone.jpg"></DIV>
This example uses inline scripting to change the position of two images when an onclick event occurs.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/left_s.htm
<BUTTON onclick="cone.style.left='100px'; sphere.style.left='200px'"> . . .</BUTTON>
See also
Send comments about this topic to Microsoft
Build date: 11/29/2012

