BackToTop
A button that appears once the page has scrolled past threshold px (300 by default) and scrolls back to the top, smoothly unless the reader prefers reduced motion (or instant). It is hidden, and out of the tab order, until it is needed. position is bottom-right (default), bottom-left or bottom-center; label names the button and is its tooltip.
On a page, just render <BackToTop />. For a scrolling panel pass target (a ref or an element) and fixed={false}, and put the button next to the scrolling element inside a relative wrapper.
Banana fact 1. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 2. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 3. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 4. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 5. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 6. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 7. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 8. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 9. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 10. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 11. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 12. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 13. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Banana fact 14. Keep scrolling: the button shows up after the first screen and takes you back to the top with a smooth scroll.
Change the corner, shape (square by default, or circle), size, or the icon (pass your own children). showProgress adds a ring that fills as the reader scrolls: see ScrollProgress.
Banana fact 1. Three buttons below: one in each bottom corner.
Banana fact 2. Three buttons below: one in each bottom corner.
Banana fact 3. Three buttons below: one in each bottom corner.
Banana fact 4. Three buttons below: one in each bottom corner.
Banana fact 5. Three buttons below: one in each bottom corner.
Banana fact 6. Three buttons below: one in each bottom corner.
Banana fact 7. Three buttons below: one in each bottom corner.
Banana fact 8. Three buttons below: one in each bottom corner.
Banana fact 9. Three buttons below: one in each bottom corner.
Banana fact 10. Three buttons below: one in each bottom corner.
Banana fact 11. Three buttons below: one in each bottom corner.
Banana fact 12. Three buttons below: one in each bottom corner.
Banana fact 13. Three buttons below: one in each bottom corner.
Banana fact 14. Three buttons below: one in each bottom corner.
Props
targetHTMLElement | RefObject<HTMLElement>Default:the pageWhat scrolls: an element or a ref to one.
thresholdnumberDefault:300Show the button after this many pixels of scrolling.
position'bottom-right' | 'bottom-left' | 'bottom-center'Default:'bottom-right'Which corner it sits in.
fixedbooleanDefault:trueFix it to the viewport;
falseplaces it inside the nearestrelativeparent.showProgressbooleanDefault:falseDraw a ring around the button that fills as the reader scrolls.
labelstringDefault:'Back to top'Name of the button, also its tooltip.
size'sm' | 'md' | 'lg'Default:'md'Size of the button.
shape'square' | 'circle'Default:'square'Shape of the button (a progress ring is always round).
childrenReactNodeDefault:an up arrowReplaces the icon.
instantbooleanDefault:falseJump to the top without the scroll animation.
classNamestringDefault:''Extra classes for the root element.
| Prop | Type | Default | Description |
|---|---|---|---|
target | HTMLElement | RefObject<HTMLElement> | the page | What scrolls: an element or a ref to one. |
threshold | number | 300 | Show the button after this many pixels of scrolling. |
position | 'bottom-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | Which corner it sits in. |
fixed | boolean | true | Fix it to the viewport; false places it inside the nearest relative parent. |
showProgress | boolean | false | Draw a ring around the button that fills as the reader scrolls. |
label | string | 'Back to top' | Name of the button, also its tooltip. |
size | 'sm' | 'md' | 'lg' | 'md' | Size of the button. |
shape | 'square' | 'circle' | 'square' | Shape of the button (a progress ring is always round). |
children | ReactNode | an up arrow | Replaces the icon. |
instant | boolean | false | Jump to the top without the scroll animation. |
className | string | '' | Extra classes for the root element. |
Related hooks and theme:useScrollProgress