JSFiddle - React, Tailwind, and code Playground

HTML

<div class="test-text">
    Scrollbar width: <span id="scrollbar"></span>
</div>

CSS

.outer {
    position: absolute;
    height: 150px;
    overflow-y: hidden;
    width: 50px;
    position: absolute;
    top: 0;
    right: 0;
}

.inner {
    height: 200px;
    width: 100%;   
}

JavaScript

function getScrollBarWidth() {
    var inner = $('<p />', {style:'width:100%;height:200px;'}),
        outer = $('<div />', {style:'position:absolute;top:0;left:0;visibility:hidden;width:200px;height:150px;overflow:hidden;'});

    outer.append(inner).appendTo($('body'));

    var w1 = inner.get(0).offsetWidth;
    outer.css('overflow', 'scroll');
    var w2 = inner.get(0).offsetWidth;
    if (w1 == w2) w2 = outer.get(0).clientWidth;

    outer.remove();
    return (w1 - w2);
};

 $('#scrollbar').text(getScrollBarWidth()+' pixels');