RizzyUI

Back To Top

RzBackToTop renders a floating action that appears after crossing a scroll threshold and uses Alpine to smoothly return the viewport to the top.

Basic Usage

The default button appears after Threshold pixels of scroll.

Scroll down to reveal the floating button.

Source
<div class="relative min-h-[150vh] p-8">
    <RzBackToTop />
</div>

Component Parameters

PropertyDescriptionTypeDefault
ChildContentOptional content. If omitted, the component renders an arrow icon.RenderFragment?null
ThresholdScroll offset in pixels before showing the control.int300
VariantApplies theme color styling.ThemeVariantThemeVariant.Default
SizeControls button and icon sizing.SizeSize.Medium
OutlineApplies outline styling as a compound variant.boolfalse
AriaLabelAccessible label for assistive technology.string?"Back to top"
AsChildMerges behavior and classes onto a supplied child element.boolfalse

Alpine API

The interactive behavior is powered by Alpine data component rzBackToTop.

State

MemberTypeDescription
visibleboolControls whether the floating action is displayed.
thresholdnumberResolved from data-threshold.

Methods

MethodSignatureDescription
init()Reads threshold, binds a passive scroll listener, and performs an immediate visibility evaluation.
scrollToTop()Scrolls to the top using smooth behavior unless reduced motion is preferred.
destroy()Removes the window scroll listener.