Skip to content

Scrollbars

Scrollbar customization used to be specific to Internet Explorer (scrollbar-*) or done through hacks.
Today, CSS offers modern and standardized solutions.


Defines the thickness of the scrollbar.

/* Possible values */
scrollbar-width: auto; /* default width */
scrollbar-width: thin; /* thinner */
scrollbar-width: none; /* hides the scrollbar */

Example:

* {
scrollbar-width: thin;
}
/* or */
html {
scrollbar-width: none;
}

Allows you to define the colors of the scrollbar (thumb) and the background (track).

/* syntax: scrollbar-color: <thumb-color> <track-color>; */
* {
scrollbar-color: #888 #eee; /* dark gray on light background */
}

WebKit-specific properties (Chrome, Edge, Safari)

Section titled “WebKit-specific properties (Chrome, Edge, Safari)”

For browsers based on WebKit and Blink, pseudo-elements are used:

SelectorTarget
::-webkit-scrollbarThe scrollbar area
::-webkit-scrollbar-thumbThe draggable part (thumb)
::-webkit-scrollbar-trackThe track (background of scrollbar)
::-webkit-scrollbar-cornerThe corner between two scrollbars

Example:

/* Scrollbar width */
*::-webkit-scrollbar {
width: 12px;
height: 12px; /* for horizontal scrollbar */
}
/* Draggable part */
*::-webkit-scrollbar-thumb {
background: #888;
border-radius: 6px;
}
/* Background part */
*::-webkit-scrollbar-track {
background: #eee;
}

Complete example (cross-browser):

/* Firefox */
* {
scrollbar-width: thin;
scrollbar-color: #666 #f0f0f0;
}
/* Chrome, Edge, Safari */
*::-webkit-scrollbar {
width: 10px;
}
*::-webkit-scrollbar-thumb {
background: #666;
border-radius: 5px;
}
*::-webkit-scrollbar-track {
background: #f0f0f0;
}

  • Always test across multiple browsers: Chrome, Firefox, Safari.
  • Use colors with sufficient contrast for accessibility.
  • Avoid making scrollbars too thin, especially for mobile users.
  • To hide a scrollbar, prefer scrollbar-width: none; (Firefox) and ::-webkit-scrollbar { display: none; } (WebKit), but be careful with accessibility.

  • The old scrollbar-* properties (Internet Explorer) are deprecated.
  • Today:
    • Firefox → scrollbar-width and scrollbar-color.
    • WebKit (Chrome, Safari, Edge) → ::-webkit-scrollbar and its sub-elements.
  • There is still no fully standardized cross-browser solution, but this combination covers 99% of current use cases.