---
title: "How do I style a scrollbar in CSS?"
description: "Use the standard scrollbar-color and scrollbar-width properties first, and keep the older ::-webkit-scrollbar pseudo-elements only as a fallback for older browsers."
url: https://www.danny.engineering/answer/css/how-do-i-style-a-scrollbar-in-css
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["CSS"]
---

# How do I style a scrollbar in CSS?

## The short answer


Use the standard properties. `scrollbar-color` takes two colours, the thumb and then the track, and `scrollbar-width` takes `auto`, `thin` or `none`. They work in Firefox and in Chrome and Edge from version 121, and Safari added `scrollbar-color` in Safari 26.2.


```css
.panel {
  overflow-y: auto;
  scrollbar-color: #8a8fa3 transparent; /* thumb, track */
  scrollbar-width: thin;
}
```


## Why it happens


For a long time there were two separate approaches. Firefox implemented the standard `scrollbar-color` and `scrollbar-width` properties from the CSS Scrollbars spec. Chrome, Edge and Safari used the non-standard `::-webkit-scrollbar` pseudo-elements, which let you style the bar, thumb and track like normal boxes, with borders, radii and gradients.


That split is why older tutorials show both. Chrome and Edge added the standard properties in version 121, and Safari added `scrollbar-color` in 26.2. Safari support for `scrollbar-width` has been less clear, so check MDN's compatibility table if a thin bar matters on Apple devices.


One detail catches people out. In Chrome and Edge 121 and later, once you set `scrollbar-color` or `scrollbar-width` on an element, the browser ignores any `::-webkit-scrollbar` rules for it. You get the standard styling or the legacy styling, never a mix.


The standard properties give you less control on purpose. You choose colours and a thinner variant; the browser and operating system decide the shape, the arrows and whether the bar overlays the content. That keeps scrollbars usable and consistent with the platform.


## How to fix it


### Use the standard properties


Set them on the element that scrolls. To style the main page scrollbar, set them on `html`.


```css
html {
  scrollbar-color: #6b7280 #f3f4f6;
}

.sidebar {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #9ca3af transparent;
}
```


`scrollbar-color` is inherited, so setting it on `html` also styles nested scroll areas unless they override it.


### Match light and dark themes


Use custom properties or `light-dark()` so the colours follow the theme, and set `color-scheme` so the browser picks matching default scrollbars where you do not style them.


```css
:root {
  color-scheme: light dark;
  scrollbar-color: light-dark(#9ca3af, #4b5563) transparent;
}
```


### Add a legacy fallback only for older browsers


If you need richer styling in older Safari versions, wrap the `::-webkit-scrollbar` rules in a feature query so modern Chrome and Edge use the standard properties.


```css
@supports not (scrollbar-color: auto) {
  .panel::-webkit-scrollbar {
    width: 8px;
  }

  .panel::-webkit-scrollbar-thumb {
    background: #8a8fa3;
    border-radius: 4px;
  }

  .panel::-webkit-scrollbar-track {
    background: transparent;
  }
}
```


### Reserve space so layout does not jump


When content grows and a scrollbar appears, the content area gets narrower and the layout shifts. `scrollbar-gutter: stable` keeps the space reserved.


```css
.list {
  overflow-y: auto;
  scrollbar-gutter: stable;
}
```


## Common pitfalls

- Mixing both approaches on one element and wondering why the `::-webkit-scrollbar` rules do nothing in Chrome. The standard properties take over.
- Putting the styles on the wrong element. They belong on the element with `overflow: auto` or `scroll`, not its parent.
- Making the thumb hard to see. Keep enough contrast between thumb and track, especially with `thin`.
- Using `scrollbar-width: none` on content people need to scroll with a mouse. It hides the only visual clue that there is more.
- Expecting a scrollbar on macOS when the system setting shows scrollbars only while scrolling. The overlay behaviour comes from the operating system.

## Related reading

- [MDN: scrollbar-color](https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-color)
- [MDN: scrollbar-width](https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-width)
- [MDN: scrollbar-gutter](https://developer.mozilla.org/en-US/docs/Web/CSS/scrollbar-gutter)
