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.

Preview

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 Component

A responsive Back to Top button designed in a skeuomorphic style, featuring dark theme support and responsive effects.

Open

Back to Top Button

Back to Top Button Component with 3D design, vibrant color scheme, and complex interactive elements for social media interfaces, using Tailwind CSS. It includes responsive design and dark theme support.

Open

Back to Top Button Component

A responsive back to top button designed with microinteractions and vibrant colors, suitable for a dashboard interface with dark mode support.

Open