Visual scroll indicators showing reading progress
Get started with scroll progress indicators in three simple steps:
| Position | CSS Override | Description |
|---|---|---|
| Top (default) | top: 0; left: 0; |
Horizontal bar at top of viewport |
| Bottom | bottom: 0; top: auto; |
Horizontal bar at bottom of viewport |
| Left | left: 0; width: 4px; height: 0; |
Vertical bar on left edge |
| Right | right: 0; left: auto; width: 4px; height: 0; |
Vertical bar on right edge |
| Size | Height (Horizontal) | Width (Vertical) |
|---|---|---|
| Thin | 2px |
2px |
| Default | 4px |
4px |
| Thick | 8px |
8px |
| Style | CSS |
|---|---|
| Default Green | background-color: #4caf50; |
| Blue | background-color: #2196f3; |
| Gradient | background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); |
| Dark | background-color: #333; |
.scroll-progress {
position: fixed;
bottom: 0; /* Change from top to bottom */
top: auto;
left: 0;
height: 4px;
background-color: #4caf50;
z-index: 1000;
width: 0;
}
.scroll-progress {
position: fixed;
top: 0;
left: 0;
width: 4px; /* Width instead of height */
height: 0; /* Will be updated by JavaScript */
background-color: #4caf50;
z-index: 1000;
}
// Update height instead of width for vertical bars
window.addEventListener('scroll', function() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = (document.documentElement.scrollHeight || document.body.scrollHeight) - document.documentElement.clientHeight;
var scrollPercent = scrollTop / scrollHeight * 100;
document.querySelector('.scroll-progress').style.height = scrollPercent + '%';
});
/* Blue theme */
.scroll-progress {
background-color: #2196f3;
}
/* Gradient */
.scroll-progress {
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
}
/* Dark theme */
.scroll-progress {
background-color: #333;
}
/* Custom brand color */
.scroll-progress {
background-color: var(--brand-primary);
}
/* Thin bar (2px) */
.scroll-progress {
height: 2px; /* For horizontal bars */
}
/* Thick bar (8px) */
.scroll-progress {
height: 8px; /* For horizontal bars */
}
/* Very prominent (12px) */
.scroll-progress {
height: 12px;
}
The scroll progress indicator calculates the scroll percentage and updates the bar width (or height for vertical bars) accordingly.
window.addEventListener('scroll', function() {
// Get current scroll position
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
// Calculate total scrollable height
var scrollHeight = (document.documentElement.scrollHeight || document.body.scrollHeight) - document.documentElement.clientHeight;
// Calculate percentage
var scrollPercent = scrollTop / scrollHeight * 100;
// Update progress bar width
document.querySelector('.scroll-progress').style.width = scrollPercent + '%';
});
scrollTop = Current vertical scroll position in pixelsscrollHeight = Total scrollable height (document height - viewport height)scrollPercent = (scrollTop / scrollHeight) × 100width property (or height for vertical bars)Subtle top bar showing reading progress through long-form content:
.scroll-progress {
height: 3px;
background-color: #2196f3;
opacity: 0.8;
}
Vertical bar on left side for technical documentation:
.scroll-progress {
position: fixed;
top: 0;
left: 0;
width: 5px;
height: 0;
background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
}
Prominent gradient bar for single-page marketing sites:
.scroll-progress {
height: 6px;
background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
Subtle light bar for dark-themed websites:
.scroll-progress {
height: 2px;
background-color: rgba(255, 255, 255, 0.7);
}
Respect user preferences for reduced motion:
/* Hide for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
.scroll-progress {
display: none;
}
}
Scroll progress works seamlessly with RSL's grid system and other components:
Content here...
More content...
The progress bar has z-index: 1000 to ensure it appears above most content. Adjust if needed:
/* Increase if you have modals or other high z-index elements */
.scroll-progress {
z-index: 9999;
}
Add a transition for smoother visual updates (optional):
.scroll-progress {
transition: width 0.1s ease-out;
}
You can have both horizontal and vertical bars simultaneously:
The scroll listener is already optimized, but for very long pages you can add throttling:
let ticking = false;
window.addEventListener('scroll', function() {
if (!ticking) {
window.requestAnimationFrame(function() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = (document.documentElement.scrollHeight || document.body.scrollHeight) - document.documentElement.clientHeight;
var scrollPercent = scrollTop / scrollHeight * 100;
document.querySelector('.scroll-progress').style.width = scrollPercent + '%';
ticking = false;
});
ticking = true;
}
});
.scroll-progress matches your HTMLwidth: 0 initially (not 100%)requestAnimationFrame shown in Pro TipsView scroll-progress.html for realistic use cases
Use playground.html as a starting point
Browse all RSL Components and examples