Back to top

Back-to-top button for lit-material: appears after scrolling, returns to the top and moves focus there; a plain anchor without JavaScript.

  • 1.8 KB gzipped
  • @lit-material/back-to-top 0.1.1
  • Renders on the server

Example

Install

npm install @lit-material/back-to-top @lit-material/tokens
import "@lit-material/back-to-top";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-back-to-top>

A "Back to top" button for long pages: it appears once the page has scrolled past threshold, and takes the reader back up — smoothly, unless they prefer reduced motion.

Properties

PropertyAttributeTypeDefaultDescription
thresholdthresholdnumber400Pixels scrolled before it appears.
targettargetstring""Id of the element at the top: scrolled to and focused. Empty: the window's top.
labellabelstring"Back to top"
visiblevisiblebooleanfalseSet while the page is scrolled past threshold; reflected.

CSS parts

PartDescription
buttonThe link.

CSS custom properties

PropertyDescription
--lit-material-back-to-top-insetDistance from the viewport's bottom and end edges (default 16px).

Source on GitHub npm