Ask Rift AI
Theme: Smoke
Layout: Contained
Background: Field
Search or ask anythingAsk Rift AI
Theme: Smoke
Layout: Contained
Background: Field
Colour mode: System

Back to top

A way back up a long page

A round button that appears in the bottom corner once the reader has scrolled a long way, and takes them back to the top. The jump is smooth unless the reader asks for reduced motion, and while it is hidden it is never a tab stop.

On this page

Scroll down this page and the button appears in the bottom corner. Set focusTarget to the main region's id so a keyboard reader continues from the top too.

Back to top

Props

Read from the same JSDoc that ships in the package's types. A required prop is marked with an asterisk.

BackToTop props
PropTypeDefaultDescription
threshold
number
640
How far, in px, the page scrolls before the button appears. `0` shows it at once.
label
string
'Back to top'
Accessible name and tooltip of the button.
focusTarget
string
The id of the element to move focus to after the jump (the page's main region, say), so a keyboard reader continues from the top too. Leave it out to keep focus on the button.
className
string
''
Additional CSS classes

Keys

A native button: the browser owns Enter and Space, and the press scrolls the page. Those keys belong to the platform, so no test of this library presses them.

tsx
// From the npm package
import { BackToTop } from 'rift-ds/components/BackToTop/BackToTop';

// Or as source you own, via the shadcn CLI
npx shadcn@latest add https://rift-ds.com/r/back-to-top.json

4.7 kB gzipped, with everything it imports. Peer dependencies are not counted.

For agents: the props, their allowed values and defaults, and the tested keys, as markdown or as a JSON schema.