Back to top button
- In research
Alpha components have not been thoroughly tested by developers. Learn more about component maturity.
The back to top button lets people go back to the top of a page without scrolling. This can be helpful on long pages. When selected, the back to top button takes you to the top of the page.
This can help people with mobility issues navigate the page more easily. It also helps people save time.
The back to top button is especially helpful for people using mobile devices. It decreases the swiping they have to do to get back to the top of a page.
The button appears when the user has scrolled past the first screen and begins to scroll back up. It disappears after 7 seconds by default. If someone scrolls again, it will reappear. If the user reaches the top of the page at any point, the button will disappear right away.
When and how to use it
We recommend installing the back to top button by default. If a page is not long enough to require scrolling, the back to top button will not appear.
How not to use it
This component has no extra guidance. Use the component as specified.
Demo and sample markup
The back to top component is integrated into this site and appears at the bottom right of the screen during a pause in scroll activity if you have scrolled down past the first screen and have begun to scroll back up.
<cagov-back-to-top data-hide-after="7000" data-label="Back to top">
npm i @cagov/ds-back-to-top
- Add the sample markup to your HTML.
- Refer to the Content model section for notes on mapping your data to the sample markup.
<script type="module" src="https://cdn.designsystem.webstandards.ca.gov/components/ds-back-to-top/v2.0.2/dist/index.js"></script>
The following CSS variables are used in this component:
All CSS variables define their own fallback value so you do not have to use additional CSS unless you want to change them. You may define your own value for the variable by adding your own style rules. Here is an example defining the global hex value for a CSS variable named “--primary-700”:
Component-specific accessibility review
- Make sure that arrow span has
- When button is not visible, make sure it has
tabindex=”-1”attributes. When button is visible, make sure those attribute are no longer there.
- Make sure that button has solid, 2px outline that uses
--accent2-500variable on focused state.
Standard accessibility review
As a component in Alpha status, this component must pass the following accessibility reviews every time a new version is published:
- Tested with the
[axe](https://www.deque.com/axe/)accessibility tool and passes all automated WCAG Level AA checks
- Reviewed with the VoiceOver screen reader on desktop
- Verified keyboard navigation and that all actionable elements of the component are reachable via keyboard commands only
- Reviewed component layout on a variety of screen sizes
This component uses the following data attributes. We provide this information to help with integrating the component into backend publishing systems or identifying content that may require translation.
|Plain text (default is “Back to top”)
|Integer (milliseconds, default is 7000)