CSS Custom Scrollbar Styling

Style scrollbars using CSS scrollbar-width and webkit pseudo-elements for consistent cross-browser visual design.

CssConfig Management

Code

.scroll-area {
  scrollbar-width: thin;
  scrollbar-color: #4f46e5 transparent;
}

.scroll-area::-webkit-scrollbar {
  width: 8px;
}

.scroll-area::-webkit-scrollbar-thumb {
  background: #4f46e5;
  border-radius: 4px;
}

CSS Custom Scrollbar Styling

Style scrollbars using CSS scrollbar-width and webkit pseudo-elements for consistent cross-browser visual design.

Code

.scroll-area {
  scrollbar-width: thin;
  scrollbar-color: #4f46e5 transparent;
}

.scroll-area::-webkit-scrollbar {
  width: 8px;
}

.scroll-area::-webkit-scrollbar-thumb {
  background: #4f46e5;
  border-radius: 4px;
}

Explanation

scrollbar-width and the ::-webkit-scrollbar pseudo-elements restyle the scrollbar to match the palette. Expected behavior: Firefox honours scrollbar-width and scrollbar-color, while Chromium and Safari honour the WebKit pseudo-elements. Limitation: no single syntax covers every engine, so both rule sets must be shipped together.

Interactive Tools for This Topic