Element: scrollLeft property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The scrollLeft property of the Element interface gets or sets the number of pixels by which an element's content is scrolled from its left edge. This value is subpixel precise in modern browsers, meaning that it isn't necessarily a whole number.

Value

A double-precision floating-point value indicating the number of pixels by which the element is currently scrolled horizontally from the origin, where a positive value means the element is scrolled to the right (to reveal more content to the right). If the element isn't scrolled at all left or right, then scrollLeft is 0. If the document is not the active document, the returned value is 0. If the document is rendered on a subpixel-precise device, then the returned value is also subpixel-precise and may contain a decimal component.

It's possible for scrollLeft to be negative if the element can be scrolled to the left from the initial containing block. For example, if the element's direction is rtl (right-to-left) and content grows to the left, then scrollLeft is 0 when the scrollbar is at its rightmost position (at the start of the scrolled content), and then increasingly negative as you scroll towards the end of the content.

Safari responds to overscrolling by updating scrollLeft beyond the maximum scroll position (unless the default "bounce" effect is disabled, such as by setting overscroll-behavior to none), while Chrome and Firefox do not.

The scrollLeft property can be set, which causes the element to scroll to the specified horizontal position, in the same way as using Element.scroll() with behavior: "auto".

Examples

HTML

html
<div id="container">
  <div id="content">Click the button to slide right!</div>
</div>

<button id="slide" type="button">Slide right</button>

CSS

css
#container {
  width: 100px;
  height: 100px;
  border: 1px solid #cccccc;
  overflow-x: scroll;
}

#content {
  width: 250px;
  background-color: #cccccc;
}

JavaScript

js
const button = document.getElementById("slide");

button.onclick = () => {
  document.getElementById("container").scrollLeft += 20;
};

Result

Specifications

Specification
CSSOM View Module
# dom-element-scrollleft

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
scrollLeft
Chrome – No support
Chrome 1 – 85 (Release date: 2008-12-11)
footnote For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Chrome – Full support
Chrome 86 (Release date: 2020-10-20)
footnote Full support
Edge – No support
Edge 12 – 85 (Release date: 2015-07-29)
footnote For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Edge – Full support
Edge 86 (Release date: 2020-10-09)
footnote Full support
Firefox – Full support
Firefox 1 (Release date: 2004-11-09)
footnote Full support
Opera – Full support
Opera 8 (Release date: 2005-04-19)
footnote Full support
Safari – Full support
Safari 1 (Release date: 2003-06-23)
footnote Full support
Chrome Android – No support
Chrome Android 18 – 85 (Release date: 2012-06-27)
footnote For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Chrome Android – Full support
Chrome Android 86 (Release date: 2020-10-20)
footnote Full support
Firefox for Android – Full support
Firefox for Android 4 (Release date: 2011-03-29)
footnote Full support
Opera Android – Full support
Opera Android 10.1 (Release date: 2010-11-09)
footnote Full support
Safari on iOS – Full support
Safari on iOS 1 (Release date: 2007-06-29)
footnote Full support
Samsung Internet – No support
Samsung Internet 1 – 13.2 (Release date: 2013-04-27)
footnote For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – No support
WebView Android 4.4 – 85 (Release date: 2013-12-09)
footnote For right-to-left elements, this property uses 0-100 (most left to most right) instead of negative values. See bug 41319147.
WebView Android – Full support
WebView Android 86 (Release date: 2020-10-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 1 (Release date: 2007-06-29)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Has more compatibility info.

See also