scrollbars – CSS-Tricks https://css-tricks.com Tips, Tricks, and Techniques on using Cascading Style Sheets. Mon, 14 Nov 2022 13:54:27 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 https://i0.wp.com/css-tricks.com/wp-content/uploads/2021/07/star.png?fit=32%2C32&ssl=1 scrollbars – CSS-Tricks https://css-tricks.com 32 32 45537868 Classy and Cool Custom CSS Scrollbars: A Showcase https://css-tricks.com/classy-and-cool-custom-css-scrollbars-a-showcase/ https://css-tricks.com/classy-and-cool-custom-css-scrollbars-a-showcase/#comments Mon, 14 Nov 2022 13:54:26 +0000 https://css-tricks.com/?p=375019 In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand with a matching scrollbar. The old-fashioned chrome scrollbar just doesn’t fit in as …


Classy and Cool Custom CSS Scrollbars: A Showcase originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
In this article we will be diving into the world of scrollbars. I know, it doesn’t sound too glamorous, but trust me, a well-designed page goes hand-in-hand with a matching scrollbar. The old-fashioned chrome scrollbar just doesn’t fit in as much.

We will be looking into the nitty gritty details of a scrollbar and then look at some cool examples.

Components of a scrollbar

This is more of a refresher, really. There are a bunch of posts right here on CSS-Tricks that go into deep detail when it comes to custom scrollbar styling in CSS.

To style a scroll bar you need to be familiar with the anatomy of a scrollbar. Have a look at this illustration:

A webpage wireframe with a scrollbar highlighting the scrollbar thumb and scrollbar track.

The two main components to keep in mind here are:

  1. The track is the background beneath the bar.
  2. The thumb is the part that the user clicks and drags around.

We can change the properties of the complete scrollbar using the vendor-prefixed::-webkit-scrollbar selector. We can give the scroll bar a fixed width, background color, rounded corners… lots of things! If we’re customizing the main scrollbar of a page, then we can use ::-webkit-scrollbar directly on the HTML element:

html::-webkit-scrollbar {
  /* Style away! */
}

If we’re customizing a scroll box that’s the result of overflow: scroll, then we can use ::-webkit-scrollbar on that element instead:

.element::-webkit-scrollbar {
  /* Style away! */
}

Here’s a quick example that styles the HTML element’s scrollbar so that it is wide with a red background:

What if we only want to change the scrollbar’s thumb or track? You guessed it — we have special prefixed pseudo-elements for those two: ::-webkit-scrollbar-thumb and ::-webkit-scrollbar-track, respectively. Here’s an idea of what’s possible when we put all of these things together:

Enough brushing up! I want to show you three degrees of custom scrollbar styling, then open up a big ol’ showcase of examples pulled from across the web for inspiration.

Simple and classy scrollbars

A custom scrollbar can still be minimal. I put together a group of examples that subtly change the appearance, whether with a slight color change to the thumb or track, or some light styling to the background.

As you can see, we don’t have to go nuts when it comes to scrollbar styling. Sometimes a subtle change is all it takes to enhance the overall user experience with a scrollbar that matches the overall theme.

Cool eye-catching scrollbars

But let’s admit it: it’s fun to go a little overboard and exercise some creativity. Here are some weird and unique scrollbars that might be “too much” in some cases, but they sure are eye-catching.

One more…

How about we take the scrollbar for a spin in a train for the thumb and tracks for the, well, the track!


Classy and Cool Custom CSS Scrollbars: A Showcase originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/classy-and-cool-custom-css-scrollbars-a-showcase/feed/ 9 375019
Strut Your Stuff With a Custom Scrollbar https://css-tricks.com/strut-your-stuff-with-a-custom-scrollbar/ https://css-tricks.com/strut-your-stuff-with-a-custom-scrollbar/#comments Fri, 24 Dec 2021 22:58:49 +0000 https://css-tricks.com/?p=358956 The first time I had my breath taken away by a humble scrollbar was on this very site. When CSS-Tricks v17 rolled out with its FAT CHONKY BOI, my jaw dropped.

I didn’t know you could do that on …


Strut Your Stuff With a Custom Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The first time I had my breath taken away by a humble scrollbar was on this very site. When CSS-Tricks v17 rolled out with its FAT CHONKY BOI, my jaw dropped.

I didn’t know you could do that on a professional site. And it would look… good?!

I appreciated so much about it—the gentle gradient, the reckless rounding, the blended background, the sheer satisfying CHONKINESS that dares you to click and wiggle it up and down just to marvel in its tactile heft. How bold! How avant-garde! What sheer, accessible, gracefully degrading delight!

Of course, because fun doesn’t last, the current CSS Tricks scrollbar is more grown-up and muted, light gray on black. Still on brand, still flexing subtle gradient muscle, but not so distracting that it detracts from the reading experience. In our ultra-functional world of MVPs and 80/20 rules, maximizing efficiency and hacking productivity, custom scrollbars evince something about craftsmanship. It says with no words what you can’t in a hundred.

Thanks to some standardization (with more on the way), the API is simple: seven pseudo-elements and eleven pseudo-classes that target (almost) every imaginable component and state of the trusty (and often overlooked) scrollbar. Sounds like a lot, but you can go very far with just three of them:

body::-webkit-scrollbar {
  /* required - the "base" of the bar - mostly for setting width */
}
 
body::-webkit-scrollbar-track {
  /* the "track" of the bar - great for customizing "background" colors */
}
 
body::-webkit-scrollbar-thumb {
  /* the actual draggable element, the star of the show! */
}

From here, it works like any other selected element, so bring your full bag of single div CSS tricks! Media queries work! Background gradients work! Transparency works! Margins with all manner of CSS units work! (Not everything works… I’d love to style cursor on my scrollbars for that authentic GeoCities look). I tried it out on my site with Lea Verou’s stash of CSS background gradients (my stash of stashes is here) and ended up with an atrocious combo of stripy barber pole (💈) for the thumb element and transparent hearts for the track. But it was most definitely mine—so much so that people have taken to calling it the “swyxbar” when I implemented a subtler version at work.

Every front-end developer should take this too far at least once in their careers. Live dangerously! Break the rules! Rage against the user agent! And maybe don’t ship scrollbars that break user expectations on a mass-market product (like Google Wave did back in the day)!


Strut Your Stuff With a Custom Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/strut-your-stuff-with-a-custom-scrollbar/feed/ 10 358956
Scrollbars on Hover https://css-tricks.com/scrollbars-on-hover/ https://css-tricks.com/scrollbars-on-hover/#comments Thu, 21 Jan 2021 01:29:40 +0000 https://css-tricks.com/?p=333018 First, scrollbars are a usability and accessibility thing. Second, a rule of thumb: if an area scrolls, it should have a visible scrollbar. But the web is a big place and I like tricks, so I’m going to cover the …


Scrollbars on Hover originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
First, scrollbars are a usability and accessibility thing. Second, a rule of thumb: if an area scrolls, it should have a visible scrollbar. But the web is a big place and I like tricks, so I’m going to cover the idea of only revealing them on hover. Even macOS itself¹ hides scrollbars by default, revealing them contextually and on interaction. Same on iOS, leading to confusing moments.

All that aside, here’s a way to hide scrollbars by default, only revealing them when the element is hovered. It was created by Thomas Gladdines, who also emailed me about it:

In quick testing on my machine, it works across Chrome, Firefox, and Safari, regardless of my macOS settings. So pretty robust.

The trick is that mask covers the scrollbar! So, if you create a mask that is exactly as wide as the scrollbar (here, I’m just guessing that 17px will cover it) and super duper tall (both of which should probably be calculated by a script), it can perfectly cover the scrollbar. You can even transition the position of the mask, faking a fading in/out effect. Very clever.

Notably, this is the real scrollbar of the element, and not a faked one. Faking one could be another approach. Ben Nadel covered how Slack does that. Their trick is to force the scrollbar to render in an area hidden by overflow, and make a virtual scrollbar that mimics the native one (which you’d then have more direct control over). It’s not forcing the scrollbar either, which is something else you can do if so motivated. And nothing about this prevents you from styling the scrollbar, which might actually have some benefits like specifying the exact width of it.

  1. As I write: If your device allows gestures, scroll bars are hidden until you start scrolling. Otherwise, they’re visible. ↩️

Scrollbars on Hover originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/scrollbars-on-hover/feed/ 8 333018
That’s Just How I Scroll https://css-tricks.com/thats-just-how-i-scroll/ https://css-tricks.com/thats-just-how-i-scroll/#comments Fri, 14 Aug 2020 20:00:33 +0000 https://css-tricks.com/?p=318581 How do you know a page (or any element on that page) scrolls? Well, if it has a scrollbar, that’s a pretty good indication. You might still have to scrapple with your client about “the fold” or whatever, but I …


That’s Just How I Scroll originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
How do you know a page (or any element on that page) scrolls? Well, if it has a scrollbar, that’s a pretty good indication. You might still have to scrapple with your client about “the fold” or whatever, but I don’t think anyone is confused at what a scrollbar is or what it indicates.

But let’s say there is no scrollbar. That’s super common. macOS hides scrollbars by default and only shows them during scroll. Most mobile browsers don’t have scrollbars, even if you attempt to force them with something like overflow: scroll;.

Why does this matter? If you don’t know an area is scrollable, you might miss out on important content or functionality.

I regularly think about the Perfectly Cropped story from Tyler Hall. There is a screen on iOS that has important functionality you need to scroll down to, but there is no indicator whatsoever that you can scroll there.

The result of that was Tyler’s mom literally not being able to find functionality she was used to. Not great.

There is an elaborate way to detect visible scrollbars and force them to be visible, but something about that rubs me the wrong way. It doesn’t honor a user’s preference (assuming it is the user’s preference), requires DOM manipulation tests, and uses vendor-prefixed CSS (which will probably live a long time, but has been standardized now, so maybe not forever).

I enjoy these approaches and by Chris Smith and his thinking:

My favorite are the shadow-based techniques. To me an inset shadow is a really clear indicator, as it makes it appear that content is flowing underneath and the shadow follows an edge that as a hint that you can scroll in that direction. Plus, you’ve got CSS control there so I’d think it could match whatever UI situation you’re in fairly easily.

It should be known though that it can be done entirely in CSS though, no JavaScript, and is one of the great CSS tricks.


That’s Just How I Scroll originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/thats-just-how-i-scroll/feed/ 7 318581
Hide Scrollbars During an Animation https://css-tricks.com/hide-scrollbars-during-an-animation/ https://css-tricks.com/hide-scrollbars-during-an-animation/#comments Wed, 24 Jun 2020 21:33:40 +0000 https://css-tricks.com/?p=313482 CSS still can’t animate to auto dimensions.

.dropdown {
  transition: 0.2s;
  height: 0;
}
.dropdown.open {
  /* the height will change, but it won't animate. */
  height: auto;
}

There is JavaScript trickery you can try. Brandon Smith outlined several


Hide Scrollbars During an Animation originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
CSS still can’t animate to auto dimensions.

.dropdown {
  transition: 0.2s;
  height: 0;
}
.dropdown.open {
  /* the height will change, but it won't animate. */
  height: auto;
}

There is JavaScript trickery you can try. Brandon Smith outlined several techniques here a little while back. My mind always goes to this solution just because it’s so simple:

.dropdown {
  transition: 0.2s;
  max-height: 0;
}
.dropdown.open {
  /* 🎉 */
  max-height: 400px;
}

Now we have this 400px magic number which is really not ideal. But the fact that this works and is so simple makes it extremely appealing that I use it production all the time.

But the magic number isn’t the only problem. Another problem is scrollbars.

When we set max-height: 0;, we also need overflow: hidden; to make sure the dropdown is actually hidden when it is closed. When the dropdown is open, we should probably be using overflow: auto; so that we don’t accidentally cut off content in case the natural height of the dropdown is taller than the max-height after it expands. The use of overflow: auto; solves that problem while introducing another: during the expansion, our dropdown will always have scrollbars for at least part of the expansion, even if the final expansion height doesn’t need them. That’s awkward!

CSS trickery to the rescue.

We can still use overflow: auto; on the expanded state — we’ll just override it during the animation. As we learned in the great CSS specificity battle, @keyframes have an amazing ability to override anything while they are active. Let’s use them not to animate the opening, but just for this scrollbar-hiding functionality:

.dropdown {
  max-height: 0;
  overflow: hidden;
  transition: max-height 1.2s ease-in-out;
}
.dropdown.open {
  overflow: auto;
  max-height: 400px;
  animation: hide-scroll 1.2s backwards;
}
@keyframes hide-scroll {
  from, to { overflow: hidden; } 
}

That does the trick!

Try adjusting the height to something less to see how you don’t see scrollbars during the animation but only at the end when they are needed. That causes a little bit of jerkiness when the scrollbar pops in, but that was acceptable in my case as it’s rare that it happens at all. If you absolutely wanted to stop the jerkiness, you’d probably apply a (custom) scrollbar at all times to the dropdown and perhaps adjust the styling of the scrollbar during the animation, if needed.


Credit here to Mr. Stephen Shaw of the fancy @keyframers for this trick. I yanked him in to help me figure it out while I was working on it for something on CodePen. We decided to turn the trick into a video for the CodePen channel showcasing Collab Mode, which we used to figure out the problem/solution:


Hide Scrollbars During an Animation originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/hide-scrollbars-during-an-animation/feed/ 4 313482
Two Browsers Walked Into a Scrollbar https://css-tricks.com/two-browsers-walked-into-a-scrollbar/ https://css-tricks.com/two-browsers-walked-into-a-scrollbar/#comments Wed, 18 Sep 2019 14:16:49 +0000 https://css-tricks.com/?p=295947 Surprise: scrollbars are complicated, especially cross-browser and cross-platform.

Sometimes they take up space and sometimes they don’t. Sometimes that is affected by a setting and sometimes it isn’t. Sometimes you can see them and sometimes you can’t unless you’re actually …


Two Browsers Walked Into a Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Surprise: scrollbars are complicated, especially cross-browser and cross-platform.

Sometimes they take up space and sometimes they don’t. Sometimes that is affected by a setting and sometimes it isn’t. Sometimes you can see them and sometimes you can’t unless you’re actually scrolling. Styling them is handled in all sorts of different ways, including some very recent developments.

Follow Zach’s journey toward thinner, native, user-preference-respecting, more aesthetic scrollbars, particularly for element-level scrollbars that ends up here.

To Shared LinkPermalink on CSS-Tricks


Two Browsers Walked Into a Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/two-browsers-walked-into-a-scrollbar/feed/ 3 295947
The Current State of Styling Scrollbars in CSS (2022 Update) https://css-tricks.com/the-current-state-of-styling-scrollbars-in-css/ https://css-tricks.com/the-current-state-of-styling-scrollbars-in-css/#comments Fri, 23 Nov 2018 15:41:02 +0000 http://css-tricks.com/?p=278812 Looking at Styling Scrollbars in CSS? Look no further, we've got you covered here. This covers how it's best done right now.


The Current State of Styling Scrollbars in CSS (2022 Update) originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Your best bet for styling scrollbars in CSS, for as much cross-browser support as possible, is to use the special ::webkit prefixed scrollbar CSS properties (Chrome & Safari will need those for now) and the standardized scrollbar-width and scrollbar-color properties (for Firefox for now).

So a basic setup would look like this:

.styled-scrollbars {
  /* Foreground, Background */
  scrollbar-color: #999 #333;
}
.styled-scrollbars::-webkit-scrollbar {
  width: 10px; /* Mostly for vertical scrollbars */
  height: 10px; /* Mostly for horizontal scrollbars */
}
.styled-scrollbars::-webkit-scrollbar-thumb { /* Foreground */
  background: #999;
}
.styled-scrollbars::-webkit-scrollbar-track { /* Background */
  background: #333;
}

Using Custom Properties for Styling Scrollbars in CSS

You could DRY that up a bit with Custom Properties, like:

.styled-scrollbars {
  --scrollbar-foreground: #999
  --scrollbar-background: #333
  /* Foreground, Background */
  scrollbar-color: var(--scrollbar-foreground) var(--scrollbar-background);
}
.styled-scrollbars::-webkit-scrollbar {
  width: 10px; /* Mostly for vertical scrollbars */
  height: 10px; /* Mostly for horizontal scrollbars */
}
.styled-scrollbars::-webkit-scrollbar-thumb { /* Foreground */
  background: var(--scrollbar-foreground);
}
.styled-scrollbars::-webkit-scrollbar-track { /* Background */
  background: var(--scrollbar-background);
}

A Sass Mixin & Other Preprocessing Options

If you’re using Sass, you could abstract the usage like this, allowing for customization parameters:

@mixin scrollbars(
  $size: 10px,
  $foreground-color: #999,
  $background-color: #333
) {
  // For Chrome & Safari
  &::-webkit-scrollbar {
    width: $size;
    height: $size;
  }
  &::-webkit-scrollbar-thumb {
    background: $foreground-color;
  }
  &::-webkit-scrollbar-track {
    background: $background-color;
  }

  // Standard version (Firefox only for now)
  scrollbar-color: $foreground-color $background-color;
}

You might think Autoprefixer could help deal with the vendor prefixing situation, but the syntaxes are so different that it doesn’t look like they are terribly interested and I don’t blame them.

If you are into the PostCSS thing, there is a postcss-scrollbar plugin though. The idea is that you write the standardized syntax and it makes the vendor prefixes versions to match. Meaning you’re limited in styling choices to what the spec provides, but that’s probably a smart move long-term anyway.

/* input */
.scrollable {
  scrollbar-color: rebeccapurple green;
  scrollbar-width: thin;
}
/* output */
.scrollable::-webkit-scrollbar-thumb {
  background-color: rebeccapurple;
}
.scrollable::-webkit-scrollbar-track {
  background-color: green;
}
.scrollable::-webkit-scrollbar-corner {
  background-color: green;
}
.scrollable::-webkit-scrollbar {
  width: 0.5rem;
  height: 0.5rem;
}
.scrollable {
  -ms-overflow-style: auto;
  scrollbar-color: rebeccapurple green;
  scrollbar-width: thin;
}

More Exotic Chrome & Safari Scrollbar Styles

The non-standard ::-webkit- properties for styling scrollbars in CSS have much more styling possibility than the standardized properties. For example, I could make the width of a vertical scrollbar extremely wide, make the background track have inset shadows, and the foreground thumb have a gradient:

Here are a bunch more fancy styles that use the vendor-prefixed approach:

There are loads of them on CodePen to browse.

A JavaScript Approach to Styled Scrollbars

If styled scrollbars are a necessity and you need very detailed design control perfectly across browsers, then you’ll probably have to reach for a JavaScript solution. There must be dozens of libraries for that. I ran across simplebar and it looks like a pretty modern one with easy instantiation. Here’s a demo of that:

Here’s another one called simple-scrollbar:

Das Surma did a very fancy tutorial that creates a custom scrollbar that doesn’t actually require any JavaScript when scrolling (good for perf), but does require some JavaScript setup code.

Custom scrollbars are extremely rare and that’s mostly due to the fact that scrollbars are one of the remaining bits on the web that are pretty much unstylable (I’m looking at you, date picker). You can use JavaScript to build your own, but that’s expensive, low fidelity and can feel laggy. In this article, we will leverage some unconventional CSS matrices to build a custom scroller that doesn’t require any JavaScript while scrolling, just some setup code.

I’ll embed a copy here:

A Cross-Browser Demo of Custom Scrollbars

It’s fairly consistent across Chrome, Safari, and Firefox:

Here’s a screenshot of that in case you’re looking on mobile or something and can’t see these:

An example of Styling Scrollbars in CSS. It's a thin scrollbar with the background in a light blue and the rounded thumb in a dark blue.

Note about Firefox on macOS

The scrollbar-width property will work no matter what, but the scrollbar-color property only works if you have “Show scroll bars: Always” checked in General System Preferences.


The Current State of Styling Scrollbars in CSS (2022 Update) originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/the-current-state-of-styling-scrollbars-in-css/feed/ 10 278812
scrollbar-gutter https://css-tricks.com/almanac/properties/s/scrollbar-gutter/ Fri, 09 Nov 2018 15:05:41 +0000 http://css-tricks.com/?page_id=278429 The scrollbar-gutter 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 …


scrollbar-gutter originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
The scrollbar-gutter 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:

  1. Content doesn’t reflow depending on if there is a scrollbar or not
  2. There is a consistent experience for users whether they have “overlay” scrollbars or not.
body {
  scrollbar-gutter: stable both-edges;
}

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” — or UA — in the spec) that indicates your scroll position relative to the total available space on the webpage.

Those have traditionally been a visual container with a sliding indicator. These are referred to as classic scrollbars. The indicator sits inside of the gutter and the gutter takes up physical real estate on the screen when it’s displayed.

Lately, though, scrollbar appearances have trended toward something much more minimal. We call those overlay scrollbars 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.

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 overflow property (or overflow-x and overflow-y) are set to the scroll value. And note that the existence of overflow-x means we have horizontal scrolling in addition to vertical scrolling.

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.

That’s where scrollbar-gutter comes in. We can spell out whether the gutter is present in it’s classic and overlay variations.

Syntax

.my-element {
  scrollbar-gutter: auto | stable && both-edges?
}

A double ampersand (&&) separates two or more components, all of which must occur, in any order.

A question mark (?) indicates that the preceding type, word, or group is optional (occurs zero or one times).

Values

  • auto (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 property of those elements are set to scroll or auto. Conversely, overlay scrollbars take up no space at all by sitting on top of the element.
  • stable: This adds a little opinionated behavior by always reserving space for the scrollbar gutter, as long as the overflow property on the same element is set to scroll or auto and we’re dealing with a classic scrollbar — even when if the box is not overflowing. Conversely, this will have no impact on an overlay scrollbar.

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.

overflow scrollbar-gutter Overflowing Not overflowing
scroll auto yes yes
stable yes yes
auto auto yes
stable yes yes
hidden auto
stable yes yes
visible, clip auto
stable

“G” represents cases where space is reserved for the scrollbar gutter, “f?” cases where space is reserved for the scrollbar gutter if force was specified, and empty cells cases where no space is reserved.

Specification Status

The scrollbar-gutter property is defined in the Overflow Module Level 4, which is in Working Draft status. That means this is still a work in progress and could change between now and the time the draft moves to Candidate Recommendation.

the Overflow Module Level 3 specification is a Working Draft as well, so that’s a good indication that (1) it will take some time for scrollbar-gutter to become a recommendation and (2) it is still very much in progress.

Browser Support

There is no browser support at the time of the last update.

More Information

https://twitter.com/bramusblog/status/1418368669986471943

scrollbar-gutter originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
278429
What’s New In CSS? https://css-tricks.com/whats-new-in-css/ Fri, 02 Nov 2018 22:44:06 +0000 http://css-tricks.com/?p=278395 Rachel hooks us up with what the CSS Working Group is talking about:

  • Styling scrollbars. This would come with properties like scrollbar-width and scrollbar-color. The best we have right now is proprietary WebKit stuff.
  • Aspect ratios. I imagine


What’s New In CSS? originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Rachel hooks us up with what the CSS Working Group is talking about:

  • Styling scrollbars. This would come with properties like scrollbar-width and scrollbar-color. The best we have right now is proprietary WebKit stuff.
  • Aspect ratios. I imagine the CSS portion of this journey will be best handled if it plays nicely with the HTML intrinsicsize stuff.
  • Matching without specificity. :where() is :matches() with no specificity, and :matches() may become :is().
  • Logical Properties shorthand. The team is discussing a shorthand syntax for Logical Properties and the possibility logical would be default over the current physical with a defined “mode” in the stylesheet.

To Shared LinkPermalink on CSS-Tricks


What’s New In CSS? originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
278395
Scroll to the Future https://css-tricks.com/scroll-to-the-future/ Thu, 19 Apr 2018 13:57:22 +0000 http://css-tricks.com/?p=269950 This is an interesting read on the current state of scrollbars and how to control their behavior across operating systems and browsers. The post also highlights a bunch of stuff I didn’t know about, like Element.scrollIntoView() and the scroll-behavior CSS …


Scroll to the Future originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
This is an interesting read on the current state of scrollbars and how to control their behavior across operating systems and browsers. The post also highlights a bunch of stuff I didn’t know about, like Element.scrollIntoView() and the scroll-behavior CSS property.

My favorite part of all though? It has to be this bit:

In the modern web, relying heavily on custom JavaScript to achieve identical behavior for all clients is no longer justified: the whole idea of “cross-browser compatibility” is becoming a thing of the past with more CSS properties and DOM API methods making their way into standard browser implementations.

In our opinion, Progressive Enhancement is the best approach to follow when implementing non-trivial scrolling in your web projects.

Make sure you can provide the best possible minimal, but universally supported UX, and then improve with modern browser features in mind.

Speaking of the cross-browser behavior of scrollbars, Louis Hoebregts also has a new post that notes how browsers do not include the scrollbar when dealing with vw units and he provides a nice way of handling it with CSS custom properties.

To Shared LinkPermalink on CSS-Tricks


Scroll to the Future originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
269950
`matrix3d()` for a Frame-Perfect Custom Scrollbar https://css-tricks.com/matrix3d-frame-perfect-custom-scrollbar/ Sat, 01 Apr 2017 12:18:32 +0000 http://css-tricks.com/?p=253352 Das Surma:

In this article we will leverage some unconventional CSS matrices to build a custom scroller that doesn’t require any JavaScript while scrolling, just some setup code.

If turning a scrollbar into a Nyan cat with near-perfect functionality isn’t …


`matrix3d()` for a Frame-Perfect Custom Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Das Surma:

In this article we will leverage some unconventional CSS matrices to build a custom scroller that doesn’t require any JavaScript while scrolling, just some setup code.

If turning a scrollbar into a Nyan cat with near-perfect functionality isn’t a CSS trick, I don’t know what is.

To Shared LinkPermalink on CSS-Tricks


`matrix3d()` for a Frame-Perfect Custom Scrollbar originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
253352
Designing for “Show scroll bars” https://css-tricks.com/designing-show-scroll-bars/ https://css-tricks.com/designing-show-scroll-bars/#comments Fri, 30 Dec 2016 13:25:58 +0000 http://css-tricks.com/?p=249403 In macOS, users have the ability to set when they want to see scrollbars in windows. This affects all windows in the operating system, including in web browsers. They have three choices:

  • Automatically based on mouse or trackpad
  • When scrolling


Designing for “Show scroll bars” originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
In macOS, users have the ability to set when they want to see scrollbars in windows. This affects all windows in the operating system, including in web browsers. They have three choices:

  • Automatically based on mouse or trackpad
  • When scrolling
  • Always

Which means you are either in a state where you see them all the time, or a state where you only see them once scrolling has been started through some other means.

The Always option is pretty straightforward. If the window needs scrolling, the scroll bar will be there. If not, it won’t be. If the scrollbar is there, it squishes the page inward to make room for it. Here’s an example where a page goes from needing scrolling to not needing it with the Always setting on:

The scrollbar appears and pushes the page narrower to fit.

This is different than the When scrolling option, in which the scrollbar overlaps the content. Here’s an example of that:

A mousewheel scroll triggers the scroll bar to appear. Mousing over the bar expands the width.

These screenshots are the reason I was thinking about this at all. We had a user write in at CodePen because they couldn’t click that notifications icon. Before I added some extra space to prevent that overlapping, some coverage was possible:

Exacerbated by the fact that this user would zoom out, making the target even smaller, to the point it would be totally consumed:

This is only really a consideration with clickable things hugging the right side of the page. If it’s ever a problem for you, adding some padding over there is likely good enough. Or make the clickable area not confined to that narrow of a target. Here in the WordPress admin, some overlap is possible, but the clickable area is big enough that it doesn’t matter:


Designing for “Show scroll bars” originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/designing-show-scroll-bars/feed/ 16 249403
Hide Scrollbar in Edge, IE 10/11 https://css-tricks.com/snippets/css/hide-scrollbar-in-edge-ie-1011/ https://css-tricks.com/snippets/css/hide-scrollbar-in-edge-ie-1011/#comments Sun, 06 Sep 2015 00:02:12 +0000 http://css-tricks.com/?page_id=207678 You can make it auto-hiding instead of always-showing:

html {
  -ms-overflow-style: -ms-autohiding-scrollbar;
}

Turns out like this:

Credit to Thierry Koblentz for digging this gem out of Jon Neal’s Sanitize.css.…


Hide Scrollbar in Edge, IE 10/11 originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
You can make it auto-hiding instead of always-showing:

html {
  -ms-overflow-style: -ms-autohiding-scrollbar;
}

Turns out like this:

Credit to Thierry Koblentz for digging this gem out of Jon Neal’s Sanitize.css.


Hide Scrollbar in Edge, IE 10/11 originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/snippets/css/hide-scrollbar-in-edge-ie-1011/feed/ 7 207678
Custom Scrollbars Mixin https://css-tricks.com/snippets/sass/custom-scrollbars-mixin/ https://css-tricks.com/snippets/sass/custom-scrollbars-mixin/#comments Wed, 28 Jan 2015 10:31:14 +0000 http://css-tricks.com/?page_id=194420 Scrollbars are one of those UI components that are present on almost every page of the internet, yet we (developers) have little to no control over it. Some browsers give us the ability to customize their appearance but for most …


Custom Scrollbars Mixin originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
Scrollbars are one of those UI components that are present on almost every page of the internet, yet we (developers) have little to no control over it. Some browsers give us the ability to customize their appearance but for most browsers including Firefox it just is not possible.

There has been some updates and standardization to styling scrollbars. See The Current State of Styling Scrollbars for the lastest, which you could port to a mixin.

Still, Chrome and Internet Explorer (yes) make it possible for us to define custom styles for scrollbars. However the syntax horribly complex, and of course, definitely not standard. Welcome to the proprietary world. This is why you might want to have a little mixin to easily customize your scrollbars. Right?

@mixin scrollbars($size, $foreground-color, $background-color: mix($foreground-color, white,  50%)) {
  // For Google Chrome
  &::-webkit-scrollbar {
    width:  $size;
    height: $size;
  }

  &::-webkit-scrollbar-thumb {
    background: $foreground-color;
  }

  &::-webkit-scrollbar-track {
    background: $background-color;
  }

  // For Internet Explorer
  & {
    scrollbar-face-color: $foreground-color;
    scrollbar-track-color: $background-color;
  }
}

Usage:

body {
  @include scrollbars(10px, pink, red);
}
.custom-area {
  @include scrollbars(.5em, slategray);
}

Example

Going further

On both browsers, there are many more options than just color and size. However, they are often overlooked so I don’t think it is worth overcrowding the mixin with these options. Feel free to build a more advanced mixin with extra options.

Further readings:


Custom Scrollbars Mixin originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
https://css-tricks.com/snippets/sass/custom-scrollbars-mixin/feed/ 3 194420
More Elegant Fix for Jumping Scrollbar Issue https://css-tricks.com/elegant-fix-jumping-scrollbar-issue/ Tue, 16 Dec 2014 15:12:18 +0000 http://css-tricks.com/?p=190938 If you move from one page of a site without a scrollbar to another with a scrollbar, you’ll see a slight layout shift as things squeeze inward a bit to make room for the scrollbar.

A classic fix was html


More Elegant Fix for Jumping Scrollbar Issue originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
If you move from one page of a site without a scrollbar to another with a scrollbar, you’ll see a slight layout shift as things squeeze inward a bit to make room for the scrollbar.

A classic fix was html { overflow-y: scroll; } to force the scrollbar all the time. Ayke van Laëthem has found a more elegant solution in html { margin-left: calc(100vw - 100%); } which works because vw accounts for the scrollbar and % doesn’t, and… just read it as there are a few more things you’ll need to be aware of anyway.

Pretty sweet for a first blog post Ayke!

To Shared LinkPermalink on CSS-Tricks


More Elegant Fix for Jumping Scrollbar Issue originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

]]>
190938