Web · Components
BackToTop
"Back to top" button: appears in the corner once the page is scrolled by threshold and scrolls smoothly to the top on press.
3 exports
Live example
Preview
Scroll the page down; the button appears in the corner and its ring shows how much you've read.
Code
Events
- Events appear here when you interact with the preview.
Import
"Back to top" button: appears in the corner once the page is scrolled by threshold and scrolls smoothly to the top on press. For long lists, blogs and docs pages.
- Progress: the ring around it fills with the read part of the page (turned off with
progress={false}). Scrolling is processed once per frame and the ring updates without a React render. - On scroll up: with
showOnScrollUpit appears only while scrolling up; it doesn't cover content while reading down. - Accessibility: after going to the top, focus moves to the
mainelement; the screen reader continues from the top. While hidden it isn't in the tab order. - Mobile: room is left for the notch and home indicator (
safe-area); with the reduced motion preference scrolling is instant.
Examples
Position of the BackToTop button on screen.
BackToTopProps
interfaceProps of the BackToTop component.
| Name | Type | Default | Description |
|---|---|---|---|
threshold? | number | 400 | Scroll distance needed for the button to appear (px). |
target? | ScrollRoot | Scrolling container: an element, a ref or a CSS selector. Defaults to the page. With a container the button sits at the container's corner (the container doesn't have to be relative; the button still stays at the screen corner). | |
position? | BackToTopPosition | "bottom-right" | Position of the button. |
progress? | boolean | true | Show reading progress in the ring? The ring fills with how much of the page has been read. |
showOnScrollUp? | boolean | false | Visible only while scrolling up? It doesn't cover content while reading down; it appears when the user wants to go back. |
focusTarget? | string | false | "main" | Where focus goes on press. So screen reader and keyboard users can continue from the top of the page, the main element (otherwise the container) is focused by default. false leaves focus where it is. |
icon? | IconProp | up arrow | Button icon. |
label? | string | "Başa dön"` (`messages.backToTop`) | Screen reader name and tooltip. |
children? | ReactNode | Text shown next to the icon (e.g. "Back to top"); when given the button becomes a pill. | |
tooltip? | TooltipProp | false | Tooltip on hover. Defaults to label; false turns it off. See TooltipProp. | |
onClick? | () => void | Called after scrolling to the top. | |
className? | string | Classes added to the button (e.g. bottom-24 to move it). |