# Get scrollbar width in JavaScript

DevFeed: [Get scrollbar width in JavaScript](<https://devfeed.tech/articles/get-scrollbar-width-in-javascript-37275.md>)

Original publisher: [Read original article](<https://muffinman.io/blog/get-scrollbar-width-in-javascript/>)

Author: Stanko

Published: 2017-12-15T00:00:00Z

Content type: tutorial

Language: en

Sources: [Stanko Tadić](<https://devfeed.tech/sources/stanko-tadic.md>)

Topics: [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>), [browser](<https://devfeed.tech/topics/browser.md>)

Tags: [browser](<https://devfeed.tech/tags/browser.md>), [browser-support](<https://devfeed.tech/tags/browser-support.md>), [function](<https://devfeed.tech/tags/function.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [window](<https://devfeed.tech/tags/window.md>)

## AI overview

A JavaScript one-liner calculates the body scrollbar width by subtracting the document's client width from the window's inner width. It returns zero when no scrollbar is shown, including on mobile devices.

## Source excerpt

Another one-liner I love, that returns body scrollbar width. If scrollbar is not shown it will return zero (including mobile devices). function getScrollbarWidth() { return window.innerWidth - document.documentElement.clientWidth; } Click on the button to try it yourself: Get scrollbar width! Browser support # Tested on: Windows: IE9, IE10, IE11, Edge MacOS: Safari, Firefox, Chrome, Opera iOS: Safari, Chrome Android: Chrome