Back to top
Overview
Back to top component is a fragment link that allows users to quickly navigate to the top of a lengthy content page.
Status
- 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>
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
Status checklist
Property | Status | Meaning |
---|---|---|
Figma library |
|
Component is available in the Figma library |
RH Elements |
|
Component is available in the RH Elements repo |
WebRH |
|
Component should be added to the WebRH repo at a later date |
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 this page.