Element.scrollWidth is a read-only instance property that measures the full width of an element’s content, including hidden overflow. Learn how it differs from clientWidth, how to detect horizontal overflow, and how it pairs with scrollLeft—with five examples and try-it labs.
01
Kind
Instance property
02
Access
Read-only
03
Type
Integer (pixels)
04
Includes
Padding & overflow
05
Status
Baseline widely
06
Pairs with
clientWidth, scrollLeft
Fundamentals
Introduction
When a box has more content than fits in its visible width, the extra content is hidden behind a horizontal scrollbar. scrollWidth tells you how wide the full content is, not just the part you can currently see.
That makes it useful for carousels, tab strips, wide tables, and any UI where you need to know whether content overflows sideways or how far scrollLeft can move.
Think of scrollWidth as “how wide would this box need to be to show all content without scrolling horizontally?”
Concept
Understanding the Property
MDN: the read-only scrollWidth property is a measurement of the width of an element’s content, including content not visible on the screen due to overflow.
Read-only — use it to measure, not assign.
Includes padding — measured like clientWidth.
Excludes border and margin — and vertical scrollbars.
Equals clientWidth when content fits — no horizontal overflow needed.
Foundation
📝 Syntax
JavaScript
scrollWidth
Value
An integer representing the total content width in CSS pixels.
Item
Detail
Type
Integer (pixels)
Access
Read-only property
Includes
Padding and hidden overflow content
Excludes
Border, margin, vertical scrollbar
Related
clientWidth, offsetWidth, scrollLeft
⚠️
Max horizontal scroll
The farthest scrollLeft can go is usually scrollWidth - clientWidth. That portable formula replaces the non-standard scrollLeftMax property.
Pattern
📋 Overflow & Max Scroll Pattern
Detect horizontal overflow, then compute the maximum scroll offset:
Element.scrollWidth 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.scrollWidth
Read-only — returns the full content width in pixels, including hidden overflow.
BaselineWidely available
Google ChromeSupported
Yes
Microsoft EdgeSupported
Yes
Mozilla FirefoxSupported
Yes
Apple SafariSupported
Yes
OperaSupported
Yes
Internet ExplorerSupported
Yes
scrollWidthBaseline
Bottom line: Use scrollWidth to measure full content width, detect horizontal overflow, and compute max scrollLeft with clientWidth.
Wrap Up
Conclusion
scrollWidth is the full-content width measurement behind many horizontal scroll patterns. It includes hidden overflow, works with clientWidth, and pairs naturally with scrollLeft for max-scroll calculations.
Compare scrollWidth with clientWidth for overflow checks
Use scrollWidth - clientWidth for max horizontal scroll
Re-measure after content or styles change
Pair with scrollLeft for progress and end-of-scroll logic
Test on real scrollable containers, not only the page body
❌ Don’t
Confuse scrollWidth with offsetWidth
Forget that border and margin are excluded
Assign el.scrollWidth = ... (read-only)
Assume width never changes after first measure
Use non-standard scrollLeftMax when this formula works
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about scrollWidth
Read-only integer width for all content, including hidden overflow.
5
Core concepts
📄01
Get only
on Element
Kind
📝02
integer
pixels
Type
🔍03
Full content
includes overflow
Use
✅04
Baseline
widely available
Status
🎯05
W − C
max scrollLeft
Tip
❓ Frequently Asked Questions
It returns the total width of an element's content, including content that is not visible because of overflow. It is a read-only measurement in pixels.
No. MDN marks Element.scrollWidth as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
clientWidth is the visible inner width of the element. scrollWidth is the full content width needed to show everything without a horizontal scrollbar. When content fits, they are usually equal.
Yes. Like clientWidth, scrollWidth includes padding but not border, margin, or a vertical scrollbar.
Compare scrollWidth and clientWidth. If scrollWidth is greater than clientWidth, the content is overflowing horizontally.
Use element.scrollWidth - element.clientWidth. That is the portable maximum for scrollLeft.
Did you know?
scrollWidth is the horizontal twin of scrollHeight. Together with clientWidth and scrollLeft, they power most carousel and sideways-scroll UI logic.