How to calculate the width of a scrollbar in browsers Back

function getScrollbarWidth() {
    var outer = document.createElement('div'); = 'hidden'; = '100px'; = 'scrollbar'; /** needed for WinJS apps */


    var widthNoScroll = outer.offsetWidth;
    /** force scrollbars */ = 'scroll';

    /** add innerdiv */
    var inner = document.createElement('div'); = '100%';

    var widthWithScroll = inner.offsetWidth;

    /** remove divs */

    return widthNoScroll - widthWithScroll;

If you want to calculate with jQuery, use the following snippet:

function getScrollbarWidth() {
    var parent = $('<div style="'
           + 'width: 50px;'
           + 'height: 50px;'
           + 'overflow: auto'
           + '"><div/></div>')
    var child  = parent.children();
    var width  = child.innerWidth() - child.height(99).innerWidth();


    return width;
Empty Comments
Sign in GitHub

As the plugin is integrated with a code management system like GitLab or GitHub, you may have to auth with your account before leaving comments around this article.

Notice: This plugin has used Cookie to store your token with an expiration.