Element.scrollLeft is an instance property that gets or sets how far an element’s content is scrolled horizontally. Learn how to read the current position, move content to the right, assign a specific value, and understand subpixel and RTL behavior—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read and set
03
Type
Number (pixels)
04
Direction
Horizontal scroll
05
Status
Baseline widely
06
Pairs with
scrollWidth, clientWidth
Fundamentals
Introduction
When a box has more content than fits horizontally, the user can scroll sideways. The scrollLeft property tells you how many pixels the content has moved from the left edge, and you can also change that value from JavaScript.
It is useful for image carousels, tab strips, horizontally scrollable tables, and any UI where you need to move content left or right programmatically.
JavaScript
const box = document.getElementById("container");
console.log(box.scrollLeft); // 0 at the start
box.scrollLeft += 20;
💡
Beginner tip
Unlike scrollHeight, which is read-only, scrollLeft can be both read and written to control horizontal scrolling.
Concept
Understanding the Property
MDN: the scrollLeft property 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.
Readable and writable — inspect or control horizontal scroll position.
Starts at 0 — when the element has not been scrolled horizontally.
Positive means scrolled right — revealing more content to the right.
Can be decimal — subpixel precision is possible on modern devices.
Element.scrollLeft is Baseline Widely available (MDN: across browsers since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline Widely available
Element.scrollLeft
Readable and writable — returns or sets horizontal scroll offset in pixels.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported
Yes
scrollLeftBaseline
Bottom line: Use scrollLeft to read or control horizontal scrolling. Increase it to move right, decrease it to move left, and remember subpixel and RTL differences.
Wrap Up
Conclusion
scrollLeft is the horizontal scroll position property. You can read it to inspect where a container is scrolled, or write to it to move content left and right programmatically.
Use scrollLeft += value for step-by-step horizontal movement
Reset with scrollLeft = 0 when returning to the start
Test on real scrollable containers, not only the page
Consider subpixel values when comparing positions
Pair with scrollWidth and clientWidth for bounds logic
❌ Don’t
Assume the value is always a whole number
Forget RTL differences in international layouts
Confuse scrollLeft with scrollWidth
Expect it to work on non-scrollable elements
Ignore user scroll position when building custom controls
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about scrollLeft
Readable and writable horizontal scroll offset in pixels.
5
Core concepts
📄01
Get/set
on Element
Kind
📝02
number
pixels
Type
🔍03
Horizontal
scroll offset
Use
✅04
Baseline
widely available
Status
🎯05
Subpixel
values possible
Tip
❓ Frequently Asked Questions
It gets or sets how many pixels the element's content is scrolled horizontally from its left edge. A positive value means the content has moved to the right.
No. MDN marks Element.scrollLeft as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
It is usually 0 when the element has not been scrolled horizontally. In some RTL layouts, behavior can differ and values may become negative as you scroll.
Yes. Modern browsers can return subpixel-precise floating-point values, so scrollLeft is not always a whole number.
Increase scrollLeft, for example: element.scrollLeft += 20. You can also assign a specific value: element.scrollLeft = 100.
scrollLeft is the current horizontal scroll position. scrollWidth is the total width of the scrollable content.
Did you know?
MDN’s slide-right demo works by simply doing container.scrollLeft += 20 each time the button is clicked.