css UI

Custom Scrollbar Styles

Cross-browser custom scrollbar styling with thin/overlay variants, Firefox support, and dark theme optimization.

Apex Logic 0 copies
css
/* Custom Scrollbar Styles - Cross Browser */

/* === Webkit (Chrome, Safari, Edge) === */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 225, 255, 0.3);
    border: 2px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

/* === Firefox === */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

/* Thin variant for nested containers */
.scroll-thin::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

.scroll-thin {
    scrollbar-width: thin;
}

/* Auto-hide scrollbar (overlay style) */
.scroll-overlay {
    overflow: auto;
}

.scroll-overlay::-webkit-scrollbar {
    width: 6px;
}

.scroll-overlay::-webkit-scrollbar-thumb {
    background: transparent;
    transition: background 0.3s;
}

.scroll-overlay:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}

/* Horizontal scroll container */
.scroll-horizontal {
    overflow-x: auto;
    overflow-y: hidden;
    display: flex;
    gap: 16px;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.scroll-horizontal > * {
    scroll-snap-align: start;
    flex-shrink: 0;
}

/* Hide scrollbar completely (for touch/carousel) */
.scroll-hidden {
    overflow: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scroll-hidden::-webkit-scrollbar {
    display: none;
}

/* Code block scrollbar accent */
pre::-webkit-scrollbar-thumb,
code::-webkit-scrollbar-thumb {
    background: rgba(0, 225, 255, 0.15);
}

pre::-webkit-scrollbar-thumb:hover,
code::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 225, 255, 0.3);
}

Tags

scrollbar custom cross-browser dark-theme

Related Snippets

typescript

React Custom Hook Patterns

css

Dark Mode Toggle with CSS

css

Glassmorphism Card Component

css

Responsive Grid System