---
title: "Scrollbar"
description: "Opt-in utilities for styling scrollbars with webkit pseudo-elements and optional Firefox properties."
canonical_url: "https://vinicunca.dev/unocss-preset/scrollbar"
---
# Scrollbar

> Opt-in utilities for styling scrollbars with webkit pseudo-elements and optional Firefox properties.

The scrollbar preset is **off** by default. Enable it with `scrollbar: true`.

```ts [uno.config.ts]
import { presetVinicunca } from '@vinicunca/unocss-preset';
import { defineConfig } from 'unocss';

export default defineConfig({
  presets: [
    presetVinicunca({
      scrollbar: true
    })
  ]
});
```

```html
<div class="scrollbar scrollbar-rounded scrollbar-w-4px h-40 overflow-auto">
  ...
</div>
```

With the default `noCompatible: true`, `scrollbar-color` rules emit nothing and `scrollbar-width` is only written for `none`. Webkit pseudo-elements still style the bar. CSS variables have **no** `un-` prefix (`--scrollbar-width`, not `--un-scrollbar-width`).

```css
.scrollbar {
  overflow: auto;
  --scrollbar-track: #f5f5f5;
  --scrollbar-thumb: #ddd;
  --scrollbar-width: 8px;
  --scrollbar-height: 8px;
  --scrollbar-track-radius: 4px;
  --scrollbar-thumb-radius: 4px;
}
.scrollbar::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: var(--scrollbar-height);
}
.scrollbar::-webkit-scrollbar-track {
  background-color: var(--scrollbar-track);
}
.scrollbar::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
}
```

## Variants

These prefixes rewrite the selector to a webkit scrollbar pseudo-element:

| Variant | Selector |
| --- | --- |
| `scrollbar:` | `::-webkit-scrollbar` |
| `scrollbar-track:` | `::-webkit-scrollbar-track` |
| `scrollbar-thumb:` | `::-webkit-scrollbar-thumb` |

The `scrollbar` shortcut already uses them (`scrollbar:scrollbar-width-[var(--scrollbar-width)]`, `scrollbar-thumb:scrollbar-background-color-[var(--scrollbar-thumb)]`, …). You can use them on any matching utility:

```html
<div class="scrollbar scrollbar-thumb:bg-primary">
```

## Shortcuts

**scrollbar** (`shortcut`): overflow: auto, custom properties, webkit width/height/colors. Firefox scrollbar-color is skipped when noCompatible is true.

**scrollbar-rounded** (`shortcut`): Applies track and thumb border-radius from --scrollbar-track-radius and --scrollbar-thumb-radius.

**scrollbar-thin** (`shortcut`): Sets --scrollbar-width and --scrollbar-height to 8px. scrollbar-width: thin is only emitted when noCompatible is false.

**scrollbar-none** (`shortcut`): scrollbar-width: none (always) and ::-webkit-scrollbar { display: none } via scrollbar:hidden.

## Color and size

`scrollbar-thumb-color-<color>` and `scrollbar-track-color-<color>` set `--scrollbar-thumb` / `--scrollbar-track` from the theme palette.

`scrollbar-(radius|w|h|track-radius|thumb-radius)-<n>`:

| Token | Sets |
| --- | --- |
| `radius` | track and thumb radius |
| `w` | width |
| `h` | height |
| `track-radius` | track radius |
| `thumb-radius` | thumb radius |

A unitless number goes through `numberToUnit` (default: divide by 4 and append `rem`). A number with a unit is used as-is:

- `scrollbar-w-4` → `--scrollbar-width: 1rem`
- `scrollbar-w-4px` → `--scrollbar-width: 4px`

> [!WARNING]
> 
> When `noCompatible` is `false`, Firefox `scrollbar-color` is used and webkit scrollbar sizing/radius no longer apply.

## Options

See [Options](https://vinicunca.dev/unocss-preset/getting-started/options#unopresetscrollbaroption) for every field. Custom `numberToUnit`:

```ts [uno.config.ts]
presetVinicunca({
  scrollbar: {
    numberToUnit: (value) => `${value}px`
  }
});
```

Then `scrollbar-w-4` generates `--scrollbar-width: 4px`.


## Sitemap

See the full [sitemap](https://vinicunca.dev/sitemap.md) for all pages.
