{"id":278429,"date":"2018-11-09T08:05:41","date_gmt":"2018-11-09T15:05:41","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=278429"},"modified":"2021-09-11T13:18:19","modified_gmt":"2021-09-11T20:18:19","slug":"scrollbar-gutter","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/almanac\/properties\/s\/scrollbar-gutter\/","title":{"rendered":"scrollbar-gutter"},"content":{"rendered":"\n
The So we’re all on the same page, a scrollbar is that thing typically on the side of the browser (formally referred to as the “user-agent” \u2014 or UA \u2014 in the spec) that indicates your scroll position relative to the total available space on the webpage.<\/p>\n\n\n\n Those have traditionally been a visual container with a sliding indicator. These are referred to as classic scrollbars<\/strong>. The indicator sits inside of the gutter and the gutter takes up physical real estate on the screen when it’s displayed.<\/p>\n\n\n\n Lately, though, scrollbar appearances have trended toward something much more minimal. We call those overlay scrollbars<\/strong> and they are either partially or fully transparent while sitting on top of the page content. In other words, unlike classic scrollbars that take up physical real estate on the screen, overlay scrollbars sit on top of the screen content.<\/p>\n\n\n\n While we’re at it, a scrollbars can pop up in other places. Besides sitting flush to the right of the browser, we will see scrollbars on HTML elements where content overflows the element and the That’s what we’re talking about. Not the indicator itself, but the container that holds it. That’s the gutter. Whether a browser uses a classic or overlay scrollbar is totally up to the UA itself. That’s not for us to decide. Such is true of the scrollbar width. The user agent defines that and gives us no control over it.<\/p>\n\n\n\n That’s where A double ampersand (&&)<\/strong> separates two or more components, all of which must occur, in any order. The Working Draft of the spec has a super handy table that breaks those definitions down into their contexts to show the relationship they have to classic and overlay scrollbars.<\/p>\n\n\n\nscrollbar-gutter<\/code> property in CSS provides flexibility to determine how the space the browser uses to display a scrollbar that interacts with the content on the screen. The spec describes it as “reserving space for the scrollbar”. The beauty of this is that now we can make sure:<\/p>\n\n\n\n
body {\n scrollbar-gutter: stable both-edges;\n}<\/code><\/pre>\n\n\n\n\n\n\n\n
overflow<\/code> property (or
overflow-x<\/code> and
overflow-y<\/code>) are set to the
scroll<\/code> value. And note that the existence of
overflow-x<\/code> means we have horizontal scrolling in addition to vertical scrolling.<\/p>\n\n\n\n
scrollbar-gutter<\/code> comes in. We can spell out whether the gutter is present in it’s classic and overlay variations.<\/p>\n\n\n
Syntax<\/h3>\n\n\n
.my-element {\n scrollbar-gutter: auto | stable && both-edges?\n}<\/code><\/pre>\n\n\n\n
A question mark (?)<\/strong> indicates that the preceding type, word, or group is optional (occurs zero or one times).<\/p>\n\n\nValues<\/h3>\n\n\n
auto<\/code> (initial value): Pretty much the default behavior described so far. Setting the property to this value allows classic scrollbars to consume real estate in the UI on elements where the
overflow<\/code> property of those elements are set to
scroll<\/code> or
auto<\/code>. Conversely, overlay scrollbars take up no space at all by sitting on top of the element.<\/li>
stable<\/code>: This adds a little opinionated behavior by always reserving space for the scrollbar gutter, as long as the
overflow<\/code> property on the same element is set to
scroll<\/code> or
auto<\/code> and<\/em> we’re dealing with a classic scrollbar \u2014 even when if the box is not<\/em> overflowing. Conversely, this will have no impact on an overlay scrollbar.<\/li><\/ul>\n\n\n\n