Back to top
On this page
Importing
Add rh-back-to-top to your page with this import statement:
<script type="module">
import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
</script>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
To learn more about installing RHDS elements on your site using an import map read our getting started docs.
Usage
<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>
<script type="module">
import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
</script>
<style>
#overflow {
min-block-size: calc(100dvh + 401px);
}
p {
font-weight: bold;
}
</style>
Copy to Clipboard
Copied!
Wrap lines
Overflow lines
rh-back-to-top
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);
}
| Slot Name | Summary | Description |
|---|---|---|
[default]
|
link text content (default slot) |
Text displayed within the back to top button. Defaults to "Back to top" if not provided.
Keep text short and action-oriented. Should clearly indicate the button will navigate
to the top of the page. Common alternatives include "Top", "Back to top", or localized
equivalents. The text appears alongside an upward caret icon. |
| Attribute | DOM Property | Description | Type | Default |
|---|---|---|---|---|
visible
|
visible |
Controls the visibility behavior of the back to top button.
Usage guidelines
|
|
|
scrollable-selector
|
scrollableSelector |
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
|
|
|
scroll-distance
|
scrollDistance |
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
|
|
|
href
|
href |
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
Accessibility
|
|
|
| Part Name | Summary | Description |
|---|---|---|
trigger
|
anchor link that triggers scroll to top |
The clickable link element that navigates to the top of the page or specified target. This part can be styled to customize the button's appearance including hover states, borders, shadows, and positioning. The button uses a pill shape with the accent color background and includes both text and an upward caret icon. |
| CSS Property | Description | Default |
|---|---|---|
--rh-back-to-top-background-color |
—
|
|
--rh-back-to-top-background-color |
var(--rh-color-accent-base)
|
| Token | Summary | Copy |
|---|---|---|
--rh-space-xl
|
|
|
--rh-color-text-primary-on-dark
|
|
|
--rh-color-text-primary-on-light
|
|
|
--rh-color-accent-base
|
|
|
--rh-space-md
|
|
|
--rh-border-radius-pill
|
|
|
--rh-line-height-body-text
|
|
|
--rh-border-width-md
|
|
|
--rh-color-border-strong-on-dark
|
|
|
--rh-color-border-strong-on-light
|
|
|
--rh-color-interactive-primary-hover
|
|
|
--rh-font-size-body-text-xs
|
|
|
--rh-space-xs
|
|
|
--rh-space-3xl
|
|
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.