Back to top button in HTML and CSS
A floating button that appears after scrolling, glides back to the top of the page and shows reading progress.
Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.
This component also comes in
The code in HTML and CSS
document.querySelectorAll("[data-bth]").forEach((button) => {
const ring = button.querySelector("[data-bth-progress]");
const target = document.getElementById(button.getAttribute("href").slice(1));
const motion = window.matchMedia("(prefers-reduced-motion: reduce)");
let frame = 0;
function update() {
frame = 0;
const max = document.documentElement.scrollHeight - window.innerHeight;
const progress = max > 0 ? Math.min(1, window.scrollY / max) : 0;
ring.style.strokeDashoffset = String(100 - progress * 100);
// The button only takes up room once the reader has gone past the first screen.<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bouton retour en haut de page</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main class="demo">
<article class="bth-article">
<header class="bth-article__header" id="bth-haut" tabindex="-1">:root {
--bth-text: #1c2b2a;
--bth-body: #3d4f4d;
--bth-muted: #52625f;
--bth-line: #d5e0dd;
--bth-link: #0f766e;
--bth-link-hover: #134e4a;
--bth-btn-bg: #134e4a;
--bth-btn-hover: #115e59;
--bth-btn-icon: #ffffff;
--bth-btn-track: rgb(255 255 255 / 0.3);
--bth-btn-ring: #5eead4;Free component: copy it freely, including for commercial projects.
Other breadcrumbs and pagination components in HTML and CSS
Breadcrumbs and pagination components in HTML and CSS
A bottom bar with Call, Directions and Free quote that tucks away while visitors read down the page and returns as soon as they scroll up. Built for tradespeople whose customers arrive on a phone.
- Tailwind
- React
- CSS
- WordPress

A slim bar at the top of the page with a message, a link and a close button; once closed, it stays hidden for the period you choose.
- Tailwind
- React
- CSS
- WordPress

A sticky sidebar table of contents for blog posts: it highlights the section being read, shows the reading time left and folds into a list under the title on mobile.
- Tailwind
- React
- CSS
- WordPress

A column of dots on the side of the page that follows the section being read and lets visitors jump to it, with a label on hover and focus.
- Tailwind
- React
- CSS
- WordPress

Step indicator
FreeAn order step indicator: finished steps clickable to go back, the current step announced, upcoming steps locked.
- Tailwind
- React
- CSS
- WordPress

Tooltips in four positions that open on hover, tap and keyboard focus, and close with Escape, as WCAG requires.
- Tailwind
- React
- CSS
- WordPress