THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Style left Property

Style Object Reference Style Object

Example

Set the left position of a <button> element:

document.getElementById("myBtn").style.left = "100px";
Try it yourself »

Definition and Usage

The left property sets or returns the left position of a positioned element.

This property specifies the left position of the element including padding, scrollbar, border and margin.

Tip: A positioned element is an element with the position property set to: relative, absolute, or fixed.

Tip: To set or return the right position of a positioned element, use the right property.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The left property is supported in all major browsers.


Syntax

Return the left property:

object.style.left

Set the left property:

object.style.left="auto|length|%|initial|inherit"

Property Values

Value Description
auto Lets the browser set the left position. This is default
length Defines the left position in length units. Negative values are allowed
% Sets the left position in % of the width of the parent element
initial Sets this property to its default value. Read about initial
inherit Inherits this property from its parent element. Read about inherit

Technical Details

Default Value: auto
Return Value: A String, representing the left position of a positioned element
CSS Version CSS2

More Examples

Example

Set the left position of a <div> element:

document.getElementById("myDIV").style.left = "100px";
Try it yourself »

Example

Using negative values - Set the left position of a <div> element:

document.getElementById("myDIV").style.left = "-100px";
Try it yourself »

Example

Return the left position of a <div> element:

alert(document.getElementById("myDiv").style.left);
Try it yourself »

Related Pages

CSS tutorial: CSS Positioning

CSS reference: left property


Style Object Reference Style Object