CSS left Property
How to use the left CSS property to set the left position of an element in combination with the position property. See the property values in use.
The left property defines the horizontal offset of a positioned element relative to its containing block.
It specifies the distance between the element's left margin edge and the left edge of its containing block. If position is set to static, the left property has no effect.
The effect of left depends on how the element is positioned (see position property).
- If
positionis set toabsoluteorfixed, theleftproperty specifies the distance between the element's left edge and the left edge of its containing block. - If
positionis set torelative, theleftproperty specifies the distance the element's left edge is moved to the right from its normal position. - If
positionis set tosticky, theleftproperty offsets the element relative to its containing block. The element behaves likerelativepositioning until it crosses a scroll threshold, after which it behaves likefixedpositioning. - If
positionis set tostatic, theleftproperty has no effect.
| Initial Value | auto |
|---|---|
| Applies to | Positioned elements. |
| Inherited | No. |
| Animatable | Yes. Position of the element is animatable. |
| Version | CSS2 |
| DOM Syntax | Object.style.left = "50px"; |
Syntax
Syntax of CSS left Property
left: auto | length | initial | inherit;Example of the left property:
Example of CSS left Property with position property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
img {
position: absolute;
left: 35px;
}
</style>
</head>
<body>
<h2>Left property example</h2>
<p>Here the left property is defined as 35px.</p>
<img src="/build/images/w3docs-logo-black.png" alt="CSS left property" />
</body>
</html>Result

Example of using the left property when the image is inside a <div> element:
Example of CSS left Property with the img tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
div {
position: relative;
height: 150px;
width: 400px;
background-color: #ccc;
color: #666;
padding: 10px;
}
img {
position: absolute;
left: 200px;
}
</style>
</head>
<body>
<h2>Left property example</h2>
<div>
<img src="/build/images/w3docs-logo-black.png" alt="CSS left property" /> This is some div element for
<br /> which the left side is defined
<br /> as 200px.
</div>
</body>
</html>Example of the left property specified with percentages:
Example of CSS left Property with percentage value
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.example {
position: absolute;
left: 20%;
top: 20%;
width: 100px;
height: 100px;
background-color: #ccc;
color: #666;
}
</style>
</head>
<body>
<h2>Left property example</h2>
<div class="example">left: 20%</div>
</body>
</html>Example of the left property with all the values:
Example of CSS left Property with auto, px and % (percentage)values
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
.box1 {
position: absolute;
left: auto;
width: 100px;
height: 100px;
background-color: #ccc;
}
.box2 {
position: absolute;
top: 190px;
left: 50px;
width: 100px;
height: 100px;
background-color: #444;
color: #fff;
}
.box3 {
position: absolute;
left: 10%;
top: 50%;
width: 100px;
height: 100px;
background-color: #666;
color: #fff;
}
.box4 {
position: absolute;
left: 20%;
top: 70%;
width: 100px;
height: 100px;
background-color: #777;
color: #fff;
}
.box5 {
position: absolute;
left: -20px;
top: 90%;
width: 100px;
height: 100px;
background-color: #999;
text-align: right;
color: #fff;
}
</style>
</head>
<body>
<h2>Left property example</h2>
<div class="box1">left: auto</div>
<div class="box2">left: 50px</div>
<div class="box3">left: 10%</div>
<div class="box4">left: 20%</div>
<div class="box5">left: -20px</div>
</body>
</html>Values
| Value | Description | Play it |
|---|---|---|
| auto | The browser will set the left edge position. It is the default value of this property. | Play it » |
| length | Sets the left edge position in px, cm etc.. Negative values are allowed. | Play it » |
| % | Sets the left edge position as a percentage of the containing block's width. Negative values are allowed. | Play it » |
| initial | Makes the property use its default value. | Play it » |
| inherit | Inherits the property from its parents element. |
Note: On positioned elements, left defines the horizontal offset from the containing block. If both left and margin-left are specified, left takes precedence for positioning calculations.
Practice
What can be achieved with the 'left' property in CSS?