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
Back To TopAlways VisibleColor ContextNo Slotted TextScroll DistanceBack To TopAlways VisibleColor ContextNo Slotted TextScroll Distance

Back To Top

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>
```

Always Visible

import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
```
main {
  display: block;
  scroll-behavior: smooth;
  max-block-size: calc(100dvh - var(--pf-demo-header-height)) !important;
}
#bottom {
  position: absolute;
  inset-block-end: 0;
}
#nav {
  block-size: calc(100dvh - var(--pf-demo-header-height, 4.375rem)); !important;
}
```
<rh-back-to-top visible="always" href="#top">Back to top</rh-back-to-top>
```

Color Context

import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
import '@rhds/elements/lib/elements/rh-context-demo/rh-context-demo.js';
/* add support for demo/fullscreen and dev server */
const b2t = document.querySelector('rh-back-to-top');
const main = document.querySelector('main, [role="main"]');
// if main isn't scrollable use window
if (window.getComputedStyle(main).overflow === 'scroll') {
  b2t.scrollableSelector = 'main';
}
```
a {
  color: var(--rh-color-interactive-blue-darker, #0066cc);
}

a:is(:hover,:focus) {
  color: var(--rh-color-interactive-blue-darkest, #003366);
}

[color-palette^="dark"] a {
  color: var(--rh-color-accent-base-on-dark, #92c5f9);
}

[color-palette^="dark"] a:is(:hover,:focus) {
  color: var(--rh-color-interactive-blue-lightest, #b9dafc);
}

main {
  display: block;
  scroll-behavior: smooth;
  max-block-size: calc(100dvh - var(--pf-demo-header-height)) !important;
}

#nav {
  block-size: calc(100dvh - var(--pf-demo-header-height, 4.375rem)) !important;
}

#overflow {
  min-block-size: calc(100dvh + 401px);
  position: relative;
}

#bottom {
  position: absolute;
  inset-block-end: 0;
}

@media (prefers-reduced-motion: reduce) {
  main {
    scroll-behavior: auto;
  }
}
```
<rh-context-demo>
  <div id="overflow">
    <a id="top" href="#bottom">Go to bottom</a>
    <p>Scroll down or press tab to see the back to top button</p>
    <a id="bottom" href="#top">Go to top</a>
  <div>


<rh-back-to-top href="#top">Back to top</rh-back-to-top>







</div></div></rh-context-demo>
```

No Slotted Text

import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
/* add support for demo/fullscreen and dev server */
const b2t = document.querySelector('rh-back-to-top');
const main = document.querySelector('main, [role="main"]');
// if main isn't scrollable use window
if (window.getComputedStyle(main).overflow === 'scroll') {
  b2t.scrollableSelector = 'main';
}
```
main {
  display: block;
  scroll-behavior: smooth;
  max-block-size: calc(100dvh - var(--pf-demo-header-height)) !important;
}

#nav {
  block-size: calc(100dvh - var(--pf-demo-header-height, 4.375rem)) !important;
}

#overflow {
  min-block-size: calc(100dvh + 401px);
  position: relative;
}

#bottom {
  position: absolute;
  inset-block-end: 0;
}

@media (prefers-reduced-motion: reduce) {
  main {
    scroll-behavior: auto;
  }
}
```
<div id="overflow">
  <a id="top" href="#bottom">Go to bottom</a>
  <p>Scroll down or press tab to see the back to top button</p>
  <a id="bottom" href="#top">Go to top</a>
  <rh-back-to-top href="#top" label="Return to top"></rh-back-to-top>
</div>
```

Scroll Distance

import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
/* add support for demo/fullscreen and dev server */
const b2t = document.querySelector('rh-back-to-top');
const main = document.querySelector('main, [role="main"]');
// if main isn't scrollable use window
if (window.getComputedStyle(main).overflow === 'scroll') {
  b2t.scrollableSelector = 'main';
}
```
main {
  display: block;
  scroll-behavior: smooth;
  max-block-size: calc(100dvh - var(--pf-demo-header-height)) !important;
}

#nav {
  block-size: calc(100dvh - var(--pf-demo-header-height, 4.375rem)) !important;
}

#overflow {
  /* scroll distance set to 50px */
  min-block-size: calc(100dvh + 51px);
  position: relative;
}

#bottom {
  position: absolute;
  inset-block-end: 0;
}

@media (prefers-reduced-motion: reduce) {
  main {
    scroll-behavior: auto;
  }
}
```
<div id="overflow">
  <a id="top" href="#bottom">Go to bottom</a>
  <p>Scroll down (50px) or press tab to see the back to top button</p>
  <a id="bottom" href="#top">Go to top</a>
  <rh-back-to-top scroll-distance="50" href="#top">Back to top</rh-back-to-top>
</div>
```

Other libraries

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

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