Back To Top

Accessible button revealed after a scroll threshold to return to the page top

View documentation

The one already on this page

Conceptual

Back to Top belongs in the layout, once. This playground renders it in the front layout, so the live button in the corner of this page is the component — scroll past 400 pixels and watch it fade in.

There is nothing to render here, because the component is already rendered — once, in resources/views/components/layouts/front.blade.php, for every page of this site. A second instance would stack on top of the first, since the preset owns the fixed bottom-end position.

Scroll this page down. Past window.scrollY > 400 the button in the corner switches to data-visible="true", drops inert, and becomes both clickable and focusable. Scroll back to the top and it reverses, including the inert, so an invisible control can never take keyboard focus.

Clicking it scrolls the window home with smooth behaviour, or with auto when prefers-reduced-motion: reduce is on.

Threshold

Conceptual

How far the page must travel before the button appears. The comparison is strictly greater than, so at exactly 800 pixels it is still hidden.

The threshold is the only scroll-related prop. There are intentionally no props for position, offset, scroll behaviour, or a tooltip — those belong to the preset and to CSS, not to the component's API.

Because this page already renders the layout instance at the default 400, a second one at 800 would only overlap it. The value is shown rather than rendered.

Variants, sizes, labels, and icons

The same variant and size axes as hw:button, defaulting to default and icon-lg. The label becomes aria-label, and slot content replaces the configured icon.
Note: this gallery neutralises the fixed position and the opacity so the buttons can be seen standing still. In real use they are always pinned to the corner.

default
outline · icon
secondary · arrow-up
ghost · slot icon

Attributes and Stimulus composition

Conceptual

Classes, styles, and extra controllers pass through. The required back-to-top controller and action stay in place, and the internal data-back-to-top-*, data-visible, and inert attributes are reserved.

Composition is the escape hatch for the things the component deliberately does not model: a safe-area offset, an analytics hook, a tooltip. Each one arrives as an ordinary attribute or through the stimulus prop.

What cannot be overridden is the wiring that makes the button work. Passing your own data-visible or inert is ignored, so the state the controller manages stays consistent with what the user can see and focus.