.scrollLeft() gets or sets the horizontal scroll position (since jQuery 1.2.6). The value is how many pixels of content are hidden to the left of the visible area — a unitless integer.
Remember
// Getter — first matched element only
$("div").scrollLeft() // e.g. 0, 120, 300
// Setter — every matched element
$("div").scrollLeft(300)
// Animate
$("div").animate({ scrollLeft: 300 }, 400)
Ensure the element can scroll horizontally, then get or set the offset.
Use a visible container with overflow that allows horizontal scrolling.
Make sure content is wider than the visible width.
Call .scrollLeft() to read, or .scrollLeft(n) to jump.
Optional: animate with .animate({ scrollLeft: n }).
Piece
Required?
Role
Scrollable element
Yes
Overflow + wide content
value (setter)
For set
Target horizontal pixels
Return (get)
—
Integer (first match)
Return (set)
—
Same jQuery object
Pseudocode
Pseudocode
if called with no args:
return firstElement.scrollLeft // pixels hidden on the left
if called with value:
for each matched element:
element.scrollLeft = value
// At far left or not scrollable → 0
// Hidden (display:none) → unreliable — show first
Reference
Cheat Sheet
Keep these facts handy for horizontal scroll.
Topic
Detail
Get
.scrollLeft() → integer
Set
.scrollLeft(300)
Since
jQuery 1.2.6
Meaning
Pixels hidden to the left
Zero
At left edge or not scrollable
Hidden
Does not work on display: none
Animate
.animate({ scrollLeft: n })
Try it
Live Preview
A small overflow box with wide content. Get, set, nudge, or reset scrollLeft and read the integer result.
Wide content for horizontal scroll demos.
Browser demo of .scrollLeft() — same idea as the examples below.
Result
$box.scrollLeft()
→ 0
Code
jQuery Examples
Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.
Example 1 — Get Current Offset
Read scrollLeft from the first matched element.
jQuery
// Overflow box with wide inner content (set up via .css in Try It)
var left = $("#box").scrollLeft();
console.log(left); // 0 at the far left
Effect. Content shifts so 300px is hidden on the left.
Verify. A getter call returns 300.
All matches. The setter updates every element in the collection.
Example 3 — Nudge Left and Right
Read the current value, add or subtract a step, then set.
jQuery
var $box = $("#box");
var step = 50;
$box.scrollLeft($box.scrollLeft() + step); // right
console.log($box.scrollLeft());
$box.scrollLeft($box.scrollLeft() - step); // left
console.log($box.scrollLeft());
Complete. The callback runs when the tween finishes.
Use. Great for tab bars and carousels — still needs a visible element.
Edge Cases & Pitfalls
Check these before wiring horizontal scroll UI.
hidden
Hidden elements ignore scrollLeft
Show the element first. Same rule applies when animating scrollLeft.
zero
0 is ambiguous
It can mean “at the left” or “not scrollable.” Confirm overflow and content width.
overflow
Need a scrollable box
Without overflow-x: auto/scroll (or equivalent) and wide content, setters have no visible effect.
get
Getter uses the first match only
Narrow with .eq() or an id when several scroll boxes share a selector.
Compatibility
Browser Support
.scrollLeft() has been available since jQuery 1.2.6. It needs a browser DOM with jQuery loaded — not Node.js without a DOM.
✓ jQuery 1.2.6+ · Browsers only
jQuery .scrollLeft()
Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery. Relies on the native scrollLeft property under the hood.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
.scrollLeft()Browsers
Bottom line: Use .scrollLeft() on visible, horizontally scrollable elements. Pair with .scrollTop() for vertical scroll.
Analysis
Performance Notes
Approach
Cost
Best for
.scrollLeft(n)
Low
Instant jumps
.animate({ scrollLeft })
Per-frame
Smooth UX (tabs, carousels)
Native el.scrollLeft
Lowest
Hot paths without jQuery
Prefer instantaneous sets for frequent updates (drag). Use short animations for intentional navigation. Avoid reading scroll position inside tight loops without need.
Remember
Key Takeaways
Role: get/set horizontal scroll in pixels.
Meaning: pixels hidden to the left of the viewport.
One line:.scrollLeft() reads or writes how far a box is scrolled horizontally — keep the element visible and scrollable.
Frequently Asked Questions
With no arguments it returns the horizontal scroll offset of the first matched element as a unitless integer (pixels hidden to the left). With a number argument it sets that offset on every matched element and returns the jQuery object for chaining.
.scrollLeft() is horizontal; .scrollTop() is vertical. Both return integers, share the same getter/setter pattern, and can be animated with .animate({ scrollLeft: n }) or .animate({ scrollTop: n }).
Hidden elements (display:none) have no scrollable layout box. Reading or animating scrollLeft on them does not work reliably. Show the element first, then read or set.
Either the bar is at the far left, or the element is not horizontally scrollable (content fits, or overflow does not allow scrolling). Check overflow and content width before assuming position.
Yes: $el.animate({ scrollLeft: target }, duration). For an instant jump, use .scrollLeft(value) instead.
For non-zero values, yes — the element needs a scrollable overflow and content wider than its visible width. Otherwise the getter stays 0 and the setter has no visible effect.