Skip to main content Home
About About the Design SystemRoadmap
Get started OverviewDesignersDevelopers
Foundations OverviewColorGridIconographyInteractionsSpacingTypography
Tokens Overview Global colorbox shadowTypographyborderopacityspacelengthIconBreakpointsMedia Queries
Elements All elements Accordion Alert Announcement Audio player Avatar Back to top Badge Blockquote Breadcrumb Button Card Chip Code block Call to action Dialog Disclosure Footer Health index Icon Jump links Navigation (primary) Navigation (secondary) Pagination PopoverPlanned Progress stepsPlanned Site status Skip link Spinner Statistic Subnavigation Surface Switch Table Tabs Tag Tile Timestamp Tooltip Video embed
Theming OverviewColor PalettesCustomizingDevelopers
Patterns All PatternsCardTabsFilterFormLinkLink with iconLogo wallSearch barSkip navigationSticky bannerSticky cardTileVideo thumbnail
Personalization All Personalization PatternsAnnouncement
Accessibility FundamentalsAccessibility toolsAssistive technologiesCI/CDContentContributorsDesignDevelopmentManual testingResourcesScreen readers
Design/code status Release notes Get support

Back to top

OverviewStyleGuidelinesCodeAccessibilityDemos
ImportingUsagerh-back-to-topImportingUsagerh-back-to-top

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 Wrap 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 Wrap 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.

Slots 1
Slot Name Description

Text for the back to top link

Attributes 4
Attribute DOM Property Description Type Default
visible visible

Flag to always show back to top button, defaults to false.

'always' | undefined | undefined
unknown
scrollable-selector scrollableSelector

Element selector to spy on for scrolling. Not passing a selector defaults to spying on window scroll events

string | undefined
unknown
scroll-distance scrollDistance

Distance from the top of the scrollable element to trigger the visibility of the back to top button

number
400
href href

Page fragment link to target element, must include hash ex: #top

string | undefined
unknown
Methods 0
None
Events 0
None
CSS Shadow Parts 1
Part Name Description
trigger

back to top link anchor element

CSS Custom Properties 0
None
Design Tokens 12
Token Copy
--rh-border-radius-pill
Full CSS Variable Permalink to this token
--rh-border-width-md
Full CSS Variable Permalink to this token
--rh-color-accent-base-on-light
Full CSS Variable Permalink to this token
--rh-color-border-strong-on-dark
Full CSS Variable Permalink to this token
--rh-color-interactive-primary-hover-on-light
Full CSS Variable Permalink to this token
--rh-color-text-primary-on-dark
Full CSS Variable Permalink to this token
--rh-font-size-body-text-xs
Full CSS Variable Permalink to this token
--rh-line-height-body-text
Full CSS Variable Permalink to this token
--rh-space-3xl
Full CSS Variable Permalink to this token
--rh-space-md
Full CSS Variable Permalink to this token
--rh-space-xl
Full CSS Variable Permalink to this token
--rh-space-xs
Full CSS Variable Permalink to this token

Other libraries

To learn more about our other libraries, visit the getting started page.

© 2021-2025 Red Hat, Inc. Deploys by Netlify