The user wants a scroll-to-top button that:
- Smoothly appears after scrolling down a webpage
- Uses HTML, CSS, and JS
- Should be well-designed, not generic
Let me create a polished, modern scroll-to-top button with:
- A distinctive design (not a generic circle with arrow)
- Smooth appearance animation
- Meaningful interactions
- Good visual hierarchy
I'll create a demo page with enough content to demonstrate the scroll functionality, and a stylish scroll-to-top button.
Design approach:
- Use a distinctive button shape (maybe rounded square or pill with interesting treatment)
- Add a progress indicator ring showing scroll progress
- Use a nice entrance/exit animation
- Subtle hover effects
- Maybe a glow or shadow effect that's not overused
Let me pick:
- Font: Something distinctive, maybe Space Grotesk for a technical feel
- Color scheme: Dark mode with a sharp accent color (maybe cyan/teal or coral)
- Button design: Rounded with a subtle border, progress ring around it
I'll make sure:
- Button appears after scrolling past a threshold
- Smooth fade in/out with scale animation
- Click smoothly scrolls to top
- Visual feedback on hover
- Includes scroll progress indicator for extra polish
- Respects prefers-reduced-motion
- Keyboard accessible
Here's a polished scroll-to-top button with a scroll progress indicator, smooth animations, and a distinctive design. I've created a full demo page so you can see it in action.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scroll to Top Button</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;500;700&family=Inter:wght@400;500&display=swap" rel="stylesheet">
<style>
:root {
--bg: #0a0f14;
--bg-secondary: #111920;
--fg: #e8edf2;
--muted: #6b7a8a;
--accent: #00d4aa;
--accent-dim: rgba(0, 212, 170, 0.15);
--card: #151d26;
--border: #243040;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html {
scroll-behavior: smooth;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--bg);
color: var(--fg);
line-height: 1.6;
}
h1, h2, h3 {
font-family: 'Space Grotesk', sans-serif;
}
/* Background pattern */
.bg-pattern {
position: fixed;
inset: 0;
background-image:
radial-gradient(circle at 20% 20%, rgba(0, 212, 170, 0.08) 0%, transparent 50%),
radial-gradient(circle at 80% 80%, rgba(0, 150, 200, 0.06) 0%, transparent 50%);
pointer-events: none;
z-index: -1;
}
.bg-grid {
position: fixed;
inset: 0;
background-image:
linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
background-size: 60px 60px;
pointer-events: none;
z-index: -1;
}
/* Scroll to top button */
.scroll-top-btn {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 56px;
height: 56px;
border: none;
background: transparent;
cursor: pointer;
z-index: 1000;
opacity: 0;
visibility: hidden;
transform: translateY(20px) scale(0.8);
transition:
opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1),
visibility 0.4s cubic-bezier(0.4, 0, 0.2, 1),
transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.scroll-top-btn.visible {
opacity: 1;
visibility: visible;
transform: translateY(0) scale(1);
}
.scroll-top-btn:hover {
transform: translateY(-4px) scale(1.05);
}
.scroll-top-btn:active {
transform: translateY(0) scale(0.95);
}
.scroll-top-btn:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 4px;
border-radius: 50%;
}
/* Progress ring */
.progress-ring {
position: absolute;
inset: 0;
transform: rotate(-90deg);
}
.progress-ring circle {
fill: none;
stroke-width: 3;
}
.progress-ring .bg-circle {
stroke: var(--border);
}
.progress-ring .progress-circle {
stroke: var(--accent);
stroke-linecap: round;
stroke-dasharray: 150.8;
stroke-dashoffset: 150.8;
transition: stroke-dashoffset 0.1s ease-out;
}
/* Button inner */
.btn-inner {
position: absolute;
inset: 6px;
background: var(--card);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid var(--border);
transition:
background 0.3s ease,
border-color 0.3s ease,
box-shadow 0.3s ease;
}
.scroll-top-btn:hover .btn-inner {
background: var(--bg-secondary);
border-color: var(--accent);
box-shadow:
0 0 20px rgba(0, 212, 170, 0.2),
inset 0 0 20px rgba(0, 212, 170, 0.05);
}
.btn-inner svg {
width: 22px;
height: 22px;
color: var(--muted);
transition:
color 0.3s ease,
transform 0.3s ease;
}
.scroll-top-btn:hover .btn-inner svg {
color: var(--accent);
transform: translateY(-2px);
}
/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
html {
scroll-behavior: auto;
}
.scroll-top-btn {
transition: opacity 0.2s ease, visibility 0.2s ease;
transform: none !important;
}
.scroll-top-btn.visible {
transform: none !important;
}
.progress-circle {
transition: none;
}
.btn-inner svg {
transition: color 0.2s ease;
transform: none !important;
}
}
/* Demo content styles */
.hero {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
text-align: center;
padding: 2rem;
}
.hero h1 {
font-size: clamp(2.5rem, 8vw, 5rem);
font-weight: 700;
letter-spacing: -0.03em;
margin-bottom: 1rem;
background: linear-gradient(135deg, var(--fg) 0%, var(--muted) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.hero p {
font-size: 1.125rem;
color: var(--muted);
max-width: 500px;
}
.scroll-indicator {
position: absolute;
bottom: 3rem;
display: flex;
flex-direction: column;
align-items: center;
gap: 0.5rem;
color: var(--muted);
font-size: 0.875rem;
animation: bounce 2s infinite;
}
@keyframes bounce {
0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
40% { transform: translateY(10px); }
60% { transform: translateY(5px); }
}
.content-section {
max-width: 800px;
margin: 0 auto;
padding: 6rem 2rem;
}
.content-section h2 {
font-size: 2rem;
font-weight: 500;
margin-bottom: 1.5rem;
color: var(--accent);
}
.content-section p {
color: var(--muted);
margin-bottom: 1.5rem;
font-size: 1.0625rem;
}
.feature-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 1.5rem;
margin-top: 3rem;
}
.feature-card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 12px;
padding: 1.5rem;
transition:
border-color 0.3s ease,
transform 0.3s ease,
box-shadow 0.3s ease;
}
.feature-card:hover {
border-color: var(--accent);
transform: translateY(-4px);
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.feature-card h3 {
font-size: 1.125rem;
font-weight: 500;
margin-bottom: 0.5rem;
}
.feature-card p {
font-size: 0.9375rem;
margin-bottom: 0;
}
</style>
</head>
<body>
<div class="bg-pattern"></div>
<div class="bg-grid"></div>
<!-- Scroll to top button -->
<button class="scroll-top-btn" id="scrollTopBtn" aria-label="Scroll to top">
<svg class="progress-ring" viewBox="0 0 52 52">
<circle class="bg-circle" cx="26" cy="26" r="24"></circle>
<circle class="progress-circle" cx="26" cy="26" r="24"></circle>
</svg>
<div class="btn-inner">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M5 15l7-7 7 7" />
</svg>
</div>
</button>
<!-- Demo content -->
<section class="hero">
<h1>Scroll Down</h1>
<p>Experience the smooth scroll-to-top button with a progress indicator showing how far you've scrolled.</p>
<div class="scroll-indicator">
<span>Scroll to explore</span>
<svg width="24" height="24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M5 12l7 7 7-7"/>
</svg>
</div>
</section>
<section class="content-section">
<h2>Why This Button?</h2>
<p>This isn't your average scroll-to-top button. It features a circular progress ring that visualizes your scroll position on the page, smooth entrance animations, and thoughtful micro-interactions that respond to your cursor.</p>
<p>The button stays hidden until you've scrolled past 300 pixels, then elegantly fades in with a satisfying spring animation. Hover over it to see the accent glow effect and the subtle arrow lift.</p>
<div class="feature-grid">
<div class="feature-card">
<h3>Progress Indicator</h3>
<p>The ring around the button fills as you scroll down, giving visual feedback on your position.</p>
</div>
<div class="feature-card">
<h3>Spring Animation</h3>
<p>Uses a carefully tuned cubic-bezier curve for a bouncy, natural entrance effect.</p>
</div>
<div class="feature-card">
<h3>Accessible</h3>
<p>Keyboard navigable with focus states, ARIA labels, and respects reduced motion preferences.</p>
</div>
</div>
</section>
<section class="content-section">
<h2>Clean Implementation</h2>
<p>Built with vanilla JavaScript, no dependencies required. The CSS uses custom properties for easy theming, and the SVG progress ring is resolution-independent.</p>
<p>The button uses IntersectionObserver-friendly scroll detection and requestAnimationFrame for smooth progress updates without performance issues.</p>
</section>
<section class="content-section">
<h2>Section Four</h2>
<p>Keep scrolling to see the progress indicator fill up. When you're ready, click the button to smoothly return to the top of the page.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.</p>
</section>
<section class="content-section">
<h2>Almost There</h2>
<p>You're getting close to the bottom now. Notice how the progress ring is nearly complete? That's the visual cue that you've scrolled through most of the content.</p>
<p>The implementation is lightweight and won't impact your page performance. It's designed to be dropped into any project with minimal adjustments.</p>
</section>
<section class="content-section" style="min-height: 60vh;">
<h2>Final Section</h2>
<p>This is the end of the demo content. The progress ring should be full now, and clicking the button will take you all the way back to the top with a smooth scroll animation.</p>
<p>Try clicking the button now to see it in action!</p>
</section>
<script>
(function() {
const scrollBtn = document.getElementById('scrollTopBtn');
const progressCircle = document.querySelector('.progress-circle');
const circumference = 2 * Math.PI * 24; // radius = 24
// Initialize stroke dasharray
progressCircle.style.strokeDasharray = circumference;
progressCircle.style.strokeDashoffset = circumference;
// Show/hide threshold
const showThreshold = 300;
let isVisible = false;
let ticking = false;
function updateButton() {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const docHeight = document.documentElement.scrollHeight - window.innerHeight;
const scrollPercent = Math.min(scrollTop / docHeight, 1);
// Update progress ring
const offset = circumference - (scrollPercent * circumference);
progressCircle.style.strokeDashoffset = offset;
// Show/hide button
const shouldShow = scrollTop > showThreshold;
if (shouldShow !== isVisible) {
isVisible = shouldShow;
scrollBtn.classList.toggle('visible', shouldShow);
}
ticking = false;
}
function onScroll() {
if (!ticking) {
requestAnimationFrame(updateButton);
ticking = true;
}
}
// Scroll event listener
window.addEventListener('scroll', onScroll, { passive: true });
// Click handler
scrollBtn.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Initial check
updateButton();
})();
</script>
</body>
</html>
Key Features
Design Highlights:
- Progress ring - The circular border fills as you scroll down, showing your position on the page
- Spring animation - Uses
cubic-bezier(0.34, 1.56, 0.64, 1) for a bouncy entrance
- Accent glow - Subtle teal glow on hover with an inner shadow
- Dark theme - Deep navy/slate palette with a vibrant teal accent
Interactions:
- Scroll detection - Button appears after scrolling 300px
- Progress visualization - Ring fills proportionally to scroll position
- Hover state - Button lifts, glows, and arrow moves up
- Active state - Scales down on click for tactile feedback
- Smooth scroll - Animated return to top
Technical Details:
- Uses
requestAnimationFrame for performant scroll tracking
passive: true event listener for better scroll performance
- Respects
prefers-reduced-motion for accessibility
- Keyboard accessible with visible focus states
- No dependencies - pure vanilla JS
Just save as an HTML file and open in a browser to see it in action!