Back To Top
The <nys-backtotop> component provides a floating button that allows users to quickly scroll back to the top of a page. It auto-appears after scrolling 1.5 viewport heights on pages that are at least 4 screens tall, and renders as a compact circle button on mobile devices.
This Back to Top button is always visible for demo purposes. In a real-world scenario, it typically remains hidden until you scroll down the page and appears in the bottom-right corner, unless specified.
<nys-backtotop id="backtotop-demo"></nys-backtotop>
Can't use NYS Design System web components in your project? Try using the CSS Variables instead.
Accessibility
The <nys-backtotop> component includes the following accessibility-focused features:
-
Renders as a
<nys-button>with the label "Back to top," providing a clear accessible name for screen readers. -
Keyboard navigable with the
Tabkey. PressingEnterorSpaceactivates the smooth-scroll behavior. -
Hidden from the tab order and screen readers when not visible, so it does not interfere with keyboard navigation on short pages.
-
On mobile, renders as a circle button with an up-chevron icon. The button retains its accessible label.
-
Uses
position: fixedpositioning, so it remains accessible regardless of scroll position.Additional accessibility test and build content is coming soon, in a new format.
Options
Position Left
By default, <nys-backtotop> will be set on the bottom-right corner. If the bottom-right corner is blocked (e.g. by a chatbot button), set the position prop to "left" to position this component in the bottom-left instead.
Sample Content on page
This is a sample content area used to demonstrate the functionality of
the Back to Top button. In an actual application,
nys-backtotop would not be visible until the user scrolls
down the page.
<nys-backtotop position="left"></nys-backtotop>
Usage
When to use this component
- Use on long-form content pages such as state policy documents, agency service directories, and program eligibility guides.
- Use on pages with extensive search results or data tables, such as a professional license lookup or business registration listing.
- Use when users need a quick way to return to the top-level navigation after scrolling through detailed content, such as a benefits application FAQ.
When to consider something else
- Don't use on pages where content fits within a single viewport without scrolling.
- If your page uses anchor-based in-page navigation (e.g., a table of contents), users already have navigation tools and a back-to-top button may be redundant.
Do
- Place exactly one
<nys-backtotop>per page, above the<nys-globalfooter>in your markup. - Set
position="left"when the bottom-right corner is occupied by another floating element, such as a chatbot button. - Let the component manage its own visibility. The auto-show behavior activates after 1.5 viewport heights on pages that are at least 4 screens tall.
Don't
- Don’t add multiple
<nys-backtotop>components to a single page. - Don’t use
<nys-backtotop>on pages where the content fits within a single viewport. - Don’t set
visiblein production unless you have a specific reason to override the auto-show behavior. Forcing visibility on short pages creates unnecessary clutter.
Properties
| Property | Type | Default |
|---|---|---|
id |
String | "" |
position |
"left" , "right" |
"right" |
visible |
boolean | false |
Style Overrides
There are no existing CSS variables for this component. Explore existing options, or propose a new one with a Component Proposal.
Events
The <nys-backtotop> component emits three custom Javascript events:
click– Emitted when the backtotop is clicked.focus- Emitted when the backtotop receives focus.blur- Emitted when the backtotop loses focus.
Event details
You can listen to these events using JavaScript:
Suggest a New Component
Do you have an idea for a new NYS Design System web component? Look through the existing proposals in our GitHub discussions board to see if someone already proposed something similar. If not, feel free to submit one.
Edit this page on GitHub (Permissions required)
Last updated: May 20, 2026