Search 71 components and 72 controllers by name, category or description.
Back To Top
Accessible button revealed after a scroll threshold to return to the page top
The one already on this page
ConceptualBack 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.
{{-- resources/views/components/layouts/front.blade.php --}}
<hw:back-to-top />
Threshold
ConceptualHow 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.
{{-- Appears only past 800px; the comparison is strictly greater than the value. --}}
<hw:back-to-top :threshold="800" />
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.
<hw:back-to-top />
<hw:back-to-top variant="outline" size="icon" />
<hw:back-to-top variant="secondary" icon="arrow-up" label="Return to page start" />
<hw:back-to-top variant="ghost" label="Return to page start">
<x-lucide-chevrons-up class="size-5" />
</hw:back-to-top>
Attributes and Stimulus composition
ConceptualClasses, 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.
<hw:back-to-top
class="my-back-to-top"
style="margin-bottom: env(safe-area-inset-bottom)"
data-controller="analytics"
data-action="click->analytics#track"
:stimulus="stimulus()->controller('tooltip')->action('tooltip', 'show', 'mouseenter')"
/>