.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.
Syntax
Start with these common calls. Keep them short and readable.
jQuery
// 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)
Call
What it does
scrollLeft()
Learn jQuery .scrollLeft(): get or set horizontal scroll offset in pixels, animate scrollLeft, compare with scrollTop, examples, pitfalls, and FAQs.
Load jQuery before your script (CDN or local file), then wrap DOM work in $(function () { ... }) when needed.
Parameters
Parameter
Description
Step 1
Use a visible container with overflow that allows horizontal scrolling.
Step 2
Make sure content is wider than the visible width.
Step 3
Call .scrollLeft() to read, or .scrollLeft(n) to jump.
Return Value
Return Value
Description
jQuery object
Most setters and traversing helpers return the jQuery collection so you can chain more methods.
Value / undefined
Getters usually return a value from the first matched element, or undefined when nothing applies.
jQuery Examples
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.
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());
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.