Scrollbar
The Scrollbar component provides custom styling for browser scrollbars, allowing you to create more visually appealing and consistent scrollbars across different elements in your application.
Dependencies
Section titled “Dependencies”None - this is a standalone CSS component.
Basic Usage
Section titled “Basic Usage”<!-- Apply scrollbar styling to an element --><div class="scrollbar-type-1"> <!-- Content with custom scrollbar --> <div style="height: 200px; overflow: auto;"> <!-- Long content that will scroll --> </div></div>
Scrollbar Types
Section titled “Scrollbar Types”<!-- Type 1: Basic scrollbar (6px width/height) --><div class="scrollbar-type-1">...</div>
<!-- Type 2: Rounded scrollbar (6px width/height with border-radius) --><div class="scrollbar-type-2">...</div>
<!-- Type 3: Larger scrollbar (10px width/height) --><div class="scrollbar-type-3">...</div>
<!-- Type 4: Larger rounded scrollbar (12px width/height with border-radius) --><div class="scrollbar-type-4">...</div>
Colored Scrollbars
Section titled “Colored Scrollbars”<!-- Red scrollbar --><div class="scrollbar-type-1 sb-red">...</div>
<!-- Green scrollbar --><div class="scrollbar-type-2 sb-green">...</div>
<!-- Blue scrollbar --><div class="scrollbar-type-3 sb-blue">...</div>
<!-- Yellow scrollbar --><div class="scrollbar-type-4 sb-yellow">...</div>
Scroll Container
Section titled “Scroll Container”<!-- Prevent overscroll effects (bouncing/rubber-banding) --><div class="scroll-container"> <!-- Scrollable content --></div>
Plugin Parameters
Section titled “Plugin Parameters”This component doesn’t have JavaScript functionality or plugin parameters as it’s a CSS-only component.
API Methods
Section titled “API Methods”This component doesn’t provide JavaScript API methods as it’s a CSS-only component.
Events
Section titled “Events”This component doesn’t trigger any events as it’s a CSS-only component.
Styling with CSS Variables
Section titled “Styling with CSS Variables”The Scrollbar component uses LESS variables for styling, which can be customized by overriding these variables in your own LESS files:
Variable | Default (Light) | Dark Mode | Description |
---|---|---|---|
@scrollbarBackgroundColor | rgb(232, 232, 232) | N/A | Background color of the scrollbar track |
@scrollbarThumbColor | rgba(101, 95, 95, 0.71) | N/A | Color of the scrollbar thumb (the draggable part) |
Example of Custom Styling
Section titled “Example of Custom Styling”// Custom scrollbar colors@scrollbarBackgroundColor: #f0f0f0;@scrollbarThumbColor: rgba(0, 120, 215, 0.7);
Available CSS Classes
Section titled “Available CSS Classes”Base Classes
Section titled “Base Classes”.scrollbar-type-1
- Basic scrollbar with 6px width/height.scrollbar-type-2
- Rounded scrollbar with 6px width/height and border-radius.scrollbar-type-3
- Larger scrollbar with 10px width/height.scrollbar-type-4
- Larger rounded scrollbar with 12px width/height and border-radius
Color Modifiers
Section titled “Color Modifiers”.sb-{color}
- Changes the scrollbar thumb color to the specified color (e.g.,.sb-red
,.sb-blue
,.sb-green
)
Utility Classes
Section titled “Utility Classes”.scroll-container
- Prevents overscroll effects (bouncing/rubber-banding) withoverscroll-behavior: contain
HTML Attributes
Section titled “HTML Attributes”This component doesn’t use any specific HTML attributes as it’s a CSS-only component. You simply apply the CSS classes to your elements.
Accessibility
Section titled “Accessibility”Custom scrollbar styling is a visual enhancement and doesn’t affect the accessibility of scrollable content. The native scrolling functionality remains intact, ensuring that keyboard navigation and screen readers can still interact with the content properly.
Browser Compatibility
Section titled “Browser Compatibility”The Scrollbar component uses both WebKit-specific pseudo-elements (::-webkit-scrollbar
, ::-webkit-scrollbar-track
, ::-webkit-scrollbar-thumb
) for Chrome, Safari, and Edge, as well as standard CSS properties (scrollbar-width
, scrollbar-color
) for Firefox.
Note that Internet Explorer does not support custom scrollbar styling.
Best Practices
Section titled “Best Practices”- Use consistent scrollbar styling throughout your application for a cohesive user experience
- Choose scrollbar colors that provide sufficient contrast against the background
- Consider using smaller scrollbars (Type 1 or Type 2) for content areas where space is limited
- Use the
.scroll-container
class on mobile-friendly interfaces to prevent unwanted overscroll effects - Be aware that custom scrollbar styling may not be visible on some touch devices where scrollbars are hidden by default
- Test your scrollbar styling across different browsers to ensure consistent appearance