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.

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

export default defineConfig({
  presets: [
    presetVinicunca({
      scrollbar: true
    })
  ]
});
<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).

.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:

VariantSelector
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:

<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>:

TokenSets
radiustrack and thumb radius
wwidth
hheight
track-radiustrack radius
thumb-radiusthumb 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
When noCompatible is false, Firefox scrollbar-color is used and webkit scrollbar sizing/radius no longer apply.

Options

See Options for every field. Custom numberToUnit:

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

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