Scroll to top

Scroll to top is a neobrutalist React component from Cruise UI. A square button in a bottom corner that appears on long pages and takes you, and your keyboard focus, back to the top. Install it with npx shadcn@latest add @cruiseui/scroll-top.

Install

Terminal

npx shadcn@latest add @cruiseui/scroll-top

First time? Installation shows the one-off components.json setup (the @cruiseui registry) and how to turn the theme on.

Example

Corners

Scroll down this page: a labelled button appears bottom-left after 300px.

When to use it

When to use

Long pages: docs, feeds, component galleries.

When not to

Short pages that fit in two screens, or as a replacement for good navigation.

Props

CruiseScrollTop

PropTypeDefaultDescription
position?"bottom-left" | "bottom-right""bottom-right"—
offset?number16Distance from the screen edges, in px (the safe area is added).
showAfter?number600Pixels scrolled before it appears.
label?string—Optional text next to the icon, e.g. "Top" (the name stays "Back to top").
targetId?string"top"id of the element that gets focus at the top (give it tabIndex={-1}).
className?string——

Usage

  • Put <div id="top" tabIndex={-1} /> first in <body> (or pass targetId), so focus has somewhere to land.
  • Use one per page. It moves up above a toast stack in the same corner.

Accessibility

  • A real <button> named "Back to top" (also when it shows the "Top" text).
  • After scrolling up, focus moves to the #top target, so the next Tab starts at the top of the page.
  • Hidden from the tab order until it appears; no smooth scroll or slide under reduced motion.