ScrollToTopButton

The ScrollToTopButton component displays a floating button that appears when you scroll down a page and allows users to quickly scroll back to the top.

Usage

Default

Scroll down the page to make the ScrollToTopButton appear. This demo uses a tall container to simulate a real scroll environment.


<div style={{ height: "200vh", padding: "2rem" }}>
  <p style={{ maxWidth: 600 }}>
    Scroll down the page to make the ScrollToTopButton appear. This demo
    uses a tall container to simulate a real scroll environment.
  </p>
  <ScrollToTop />
</div>

Props

Data table
TypeDescription
aria-describedbystringOptional accessible description id applied to the button.
aria-labelstringAccessible label for the scroll-to-top button.
aria-labelledbystringOptional id of an external label element applied to the button. When provided, this takes precedence over "aria-label" for accessible naming.
classNamestringAdditional custom class names for the root element of the component.
data-testidstringTest identifier for the component, used to target it in testing frameworks.
idstringOptional id for the root element.
offsetnumberThe scroll offset (in pixels) from the top of the page at which the button becomes visible.
roleReact.AriaRoleOptional role for the outer wrapper if semantic grouping is needed.
roundingRoundingTypeOptional rounding style applied to the button.
shadowShadowTypeOptional shadow style for the button.
titlestringOptional title attribute for the button. Defaults to the same value as "aria-label" when not provided.
wrapperAriaLabelstringOptional accessible label for the wrapper when a semantic role is used.