MDN wants to learn about developers like you:


« DOM Reference


scrollLeft gets or sets the number of pixels that an element's content is scrolled to the left.

Note that if the element's direction is 'rtl' (right-to-left) then scrollLeft is zero when the scrollbar is at its rightmost position (at start of the scrolled content) and then increasingly negative as you scroll towards the end of the content.

Syntax and values

// Get the number of pixels scrolled
var sLeft = element.scrollLeft;

sLeft is an integer representing the number of pixels that element has been scrolled to the left.

// Set the number of pixels scrolled
element.scrollLeft = 10;

scrollLeft can be set to any integer value, however:

  • If the element can't be scrolled (e.g. it has no overflow), scrollLeft is set to 0.
  • If set to a value less than 0 (greater than 0 for right-to-left elements), scrollLeft is set to 0.
  • If set to a value greater than the maximum that the content can be scrolled, scrollLeft is set to the maximum.


<!DOCTYPE html>
    <meta charset="utf-8">
        #container {
            border: 1px solid #ccc; height: 100px; overflow: scroll; width: 100px;
        #content {
            background-color: #ccc; width: 250px;
        document.addEventListener('DOMContentLoaded', function () {   
            var button = document.getElementById('slide');
            button.onclick = function () {
                document.getElementById('container').scrollLeft += 20;
        }, false);
    <div id="container">
        <div id="content">Lorem ipsum dolor sit amet.</div>
    <button id="slide" type="button">Slide</button>


DOM Level 0. Not part of any standard.


MSDN: scrollLeft Property

Document Tags and Contributors

 Last updated by: Anonymous,