Back to top
On this page
Overview
Back to top component is a fragment link that allows users to quickly navigate to the top of a lengthy content page.
.custom-theme {
--rh-back-to-top-background-color: var(--custom-brand-color);
}
Edit element properties
import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
#overflow {
min-block-size: calc(100dvh + 401px);
}
p {
font-weight: bold;
}
<div id="overflow">
<p>Scroll down to reveal the back to top element</p>
<rh-back-to-top href="#">Back to top</rh-back-to-top>
</div>
Controls the visibility behavior of the back to top button.
undefined(default) - Button appears automatically after scrolling pastscroll-distancealways- Button is always visible, ignoring scroll position
Usage guidelines
- Use the default behavior for most cases to avoid cluttering the viewport
- Use
visible="always"only for testing or special use cases where the button should be permanently visible regardless of scroll position
<rh-back-to-top visible="always">Back to top</rh-back-to-top>
CSS selector for the element to monitor for scroll events.
When not provided, the component monitors the window's scroll position (default behavior). When provided, monitors the specified element's scroll position instead.
Usage guidelines
- Use the default (window scrolling) for standard page layouts
- Set a selector when the main scrollable content is within a specific container element
- The selector must point to a scrollable element (with overflow: auto or scroll)
- Useful for single-page applications with scrollable panels
<rh-back-to-top scrollable-selector="#main-content">Back to top</rh-back-to-top>
Distance in pixels from the top of the scrollable element to trigger button visibility.
The button appears when the user scrolls past this threshold and disappears when scrolling back above it. Default is 400px.
Usage guidelines
- Default 400px works well for most standard page layouts
- Increase for longer pages where users need more scroll before the button appears
- Decrease for shorter pages or containers where users reach the bottom quickly
- Consider page fold height and content length when customizing
<rh-back-to-top scroll-distance="800">Back to top</rh-back-to-top>
Page fragment identifier (anchor) for the target element to scroll to.
Must be a hash link pointing to an element ID on the page. The hash symbol (#) is automatically prepended if not provided.
Usage guidelines
- The target element should be near the top of the page (typically the page title or skip link)
- Ensure the target element has a matching
idattribute - Common targets:
#top,#main,#content, or the page's main heading ID - Without this attribute, clicking the button scrolls to the top of the page/container
Accessibility
- The href creates a proper anchor link for keyboard and screen reader users
- Provides a fallback navigation method if JavaScript is disabled
<rh-back-to-top href="#top">Back to top</rh-back-to-top>
Status
- Figma library:
-
Ready - RH Elements:
-
Ready - RH Shared Libs:
-
Planned
When to use
- When content fills up more than two screens in length at medium and large breakpoints
- When content fills up more than four screens in length at small breakpoints
Status checklist
| Property | Status | Meaning |
|---|---|---|
| Figma library |
|
Component is available in the Figma library |
| RH Elements |
|
Component is available in RH Elements |
| RH Shared Libs |
|
Component will be added to RH Shared Libs |
Other libraries
To learn more about our other libraries, visit this page.
Feedback
To give feedback about anything on this page, contact us.
Other libraries
To learn more about our other libraries, visit the getting started page.