Style left property

Definition and Usage

left Sets or returns the left position of the located element.

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

Tip:The positioning element is set with position property to:relative,absolute or fixed elements.

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

See also:

CSS Tutorial:CSS Positioning

CSS Reference Manual:left property

Example

Example 1

Set the left position of the <button> element:

document.getElementById("myBtn").style.left = "100px";

Try It Yourself

Example 2

Set the left position of the <div> element:

document.getElementById("myDIV").style.left = "100px";

Try It Yourself

Example 3

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

document.getElementById("myDIV").style.left = "-100px";

Try It Yourself

Example 4

Return the left position of the <div> element:

alert(document.getElementById("myDiv").style.left);

Try It Yourself

Syntax

Return left property:

object.style.left

Set left property:

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

Property Value

Value Description
auto Let the browser set the left position. Default.
length Define the left position with length units. Negative values are allowed.
% Sets the left position with the percentage of the parent element's width.
initial Sets this property to its default value. See initial.
inherit Inherits this property from its parent element. See inherit.

Technical Details

Default value: auto
Return value: A string that represents the left position of the located element.
CSS Version: CSS2

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support