Back to Top Button
A minimal and responsive "Back to Top" button component with dark mode support. It appears after scrolling down and uses smooth scrolling to return the user to the top of the page when clicked. No JavaScript is used for the scrolling, only CSS.
HTML Code
<div class="fixed bottom-4 right-4">
<a href="#" class="bg-blue-500 text-white p-3 rounded-full shadow-md transition-opacity duration-300 opacity-0 group-hover:opacity-100 dark:bg-blue-700 dark:text-gray-200">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path></svg>
</a>
</div>
<style>
/* This simple example uses CSS for smooth scrolling. For a production site, you might use a small amount of JavaScript for better compatibility and control over the scroll behavior and when the button appears. */
html {
scroll-behavior: smooth;
}
/* Basic example to show/hide the button based on scroll position.
A robust solution would involve JavaScript Intersection Observer or scroll events. */
body:before {
content: "";
height: 200vh; /* Simulate a long page */
display: block;
}
.group-hover\:opacity-100:hover + .fixed a {
opacity: 1; /* This part is flawed for demonstrating scroll-based visibility without JS */
}
/* A better approach for scroll-based visibility would require JavaScript */
.fixed a {
/* Initially hidden, JS would make it visible on scroll */
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
</style>
Related Components
Back to Top Button
A minimalist 'Back to Top' button with responsive effects and dark theme support using Tailwind CSS.
Back to Top Button Component
A responsive 'Back to Top' button with an artistic watercolor design, autumn color scheme, and dark mode support, suitable for blog/content sites.
Back to Top Button
A responsive Back to Top button component designed with a glassmorphism effect, suitable for professional business websites. It features a simple layout with minimal elements and works well in both light and dark themes.