# Back to Top Button

> A floating round button that smoothly scrolls the page back to the top.

- Category: [CSS Navigation](https://copy-css.com/category/navigation)
- Tags: scroll, top, fixed, smooth scroll, anchor
- Live preview: https://copy-css.com/snippets/back-to-top
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<a class="to-top" href="#top" aria-label="Back to top">
  <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 19V5M5 12l7-7 7 7"/></svg>
</a>
```

## CSS

```css
/* Smooth scrolling for anchor links (respects reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

.to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #0d9488;
  box-shadow: 0 8px 20px -6px rgba(13, 148, 136, 0.6);
  color: #fff;
  transition: transform 0.2s ease, background 0.2s ease;
}

.to-top:hover {
  background: #0f766e;
  transform: translateY(-3px);
}
```

## Notes

- This CSS Back to Top Button is 24 lines of pure CSS (0.5 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and CSS Grid.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
