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
Figma library
Ready
Responsive
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>
View the <rh-back-to-top> demo in a new tab

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
Responsive Ready Component responds to changing viewport sizes in Figma and the browser
RH Elements Ready Component is available as a web component
webRH Planned Component is scheduled to become a web component
© 2021-2024 Red Hat, Inc. Deploys by Netlify