Back to top
A round button in the corner that takes the reader back to the top of a long page. It appears once a screen has scrolled by, and its ring fills up as you read, so it doubles as a "how far am I" meter.
Back to top
This page has one: scroll down a little and look at the bottom-right corner.
<a class="back-to-top" href="#top" aria-label="Back to top"><i class="mi mi-arrow-up" aria-hidden="true"></i></a>
<span class="text-muted">The button sits in the corner of the window, not here.</span>It scrolls up smoothly (instantly if the reader prefers less motion) and moves keyboard focus to the top too, so Tab carries on from the page title. It is a link, so without JavaScript it still works and simply always shows.
Plain
.back-to-top-plain drops the progress ring for a simple outlined button.
<a class="back-to-top back-to-top-plain" href="#top" aria-label="Back to top"><i class="mi mi-arrow-up"></i></a>
Classes
| Class | Does |
|---|---|
.back-to-top | The button, fixed in the bottom corner (the end side, so the left in right-to-left pages) |
.back-to-top-plain | No progress ring |
.is-hidden | Set by Momo while the page is near the top |
--top-progress | 0 to 1, set by Momo as the page scrolls; the ring follows it |
Put one at the end of <body>. Point href at an element with that id (or leave #top, and focus goes to the page's h1).
Accessibility
- It needs a name:
aria-label="Back to top". - When hidden it is out of the Tab order too, so keyboard users don't land on an invisible button.