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 page

    What scrolls: an element or a ref to one.

  • thresholdnumber
    Default: 300

    Show the button after this many pixels of scrolling.

  • position'bottom-right' | 'bottom-left' | 'bottom-center'
    Default: 'bottom-right'

    Which corner it sits in.

  • fixedboolean
    Default: true

    Fix it to the viewport; false places it inside the nearest relative parent.

  • showProgressboolean
    Default: false

    Draw a ring around the button that fills as the reader scrolls.

  • labelstring
    Default: '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).

  • childrenReactNode
    Default: an up arrow

    Replaces the icon.

  • instantboolean
    Default: false

    Jump to the top without the scroll animation.

  • classNamestring
    Default: ''

    Extra classes for the root element.

Related hooks and theme:useScrollProgress