Skip to main content Red Hat Design System logo Contribute on Github

Back to top

Overview Style Guidelines Code Accessibility

Overview

Back to top component is a fragment link that allows users to quickly navigate to the top of a lengthy content page.

Example of a back to top button

Status

What do these mean?
Figma library:
Ready
RH Elements:
Ready
WebRH:
Planned

Sample

View a demo below.

Demos

View a live version of this component and see how it can be customized.

<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">Back to top</rh-back-to-top>
</div>
<script type="module">
import '@rhds/elements/rh-back-to-top/rh-back-to-top.js';
import '@patternfly/elements/pf-icon/pf-icon.js';
</script>

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

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

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

#bottom {
position: absolute;
bottom: 0;
}

@media (prefers-reduced-motion: reduce) {
main {
scroll-behavior: auto;
}
}
</style>

<script type="module">
/* add support for demo/fullscreen and dev server */
const b2t = document.querySelector('rh-back-to-top');
const main = document.querySelector('main');
// if main isn't scrollable use window
if (window.getComputedStyle(main).overflow === 'scroll') {
b2t.scrollableSelector = 'main';
}
</script>
Full screen demo

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

Property Status Meaning
Figma library Ready Component is available in the Figma library
RH Elements Ready Component is available in the RH Elements repo
WebRH Planned Component should be added to the WebRH repo at a later date

Other libraries

To learn more about our other libraries, visit this page.

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