# react-scroll-to-top

> A lightweight and customizable button component that scrolls to the top of a page when pressed The button is only visible once a certain height has been reached on the page

Latest version **3.1.0** (published 2025-04-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-scroll-to-top
pnpm add react-scroll-to-top
yarn add react-scroll-to-top
bun add react-scroll-to-top
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2025-04-05 |
| First published | 2020-05-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 67 |
| Author | Herman Nygaard |
| Maintainers | hermannygaard |
| Keywords | react, top, scroll, scroll-to-top, scroll up |

## Links

- npm: https://www.npmjs.com/package/react-scroll-to-top
- Repository: https://github.com/HermanNygaard/react-scroll-to-top
- Homepage: https://github.com/HermanNygaard/react-scroll-to-top#readme
- Issues: https://github.com/HermanNygaard/react-scroll-to-top/issues
- npm.io page: https://npm.io/package/react-scroll-to-top

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2025-04-05
- 2.0.4-beta.0 (beta) — 2022-07-23
- 3.0.0 — 2022-07-23
- 2.0.4 — 2022-07-23
- 2.0.3-beta.2 — 2022-07-23
- 2.0.3-beta.1 — 2022-07-23
- 2.0.3-beta.0 — 2022-07-23
- 2.0.2 — 2022-07-23
- 2.0.1-beta — 2022-07-23
- 2.0.0-beta — 2022-07-23
- 1.0.9 — 2022-07-06
- 1.0.8 — 2021-12-09
- 1.0.7 — 2021-12-08
- 1.0.6 — 2021-12-08
- 1.0.5 — 2020-07-15
- … 18 more at https://npm.io/package/react-scroll-to-top/versions

## README

# react-scroll-to-top

A lightweight and customizable button component that scrolls to the top of a page when pressed  
The button is only visible once a certain height has been reached on the page

[![NPM](https://nodei.co/npm/react-scroll-to-top.png)](https://nodei.co/npm/react-scroll-to-top/)

## Live demo

[A live demo can be found here](https://codesandbox.io/s/react-scroll-to-top-demo-rmuvx?file=/src/App.js)

## Installation

With npm:

`npm i react-scroll-to-top`

or with Yarn:

`yarn add react-scroll-to-top`

## Usage

Import and then add `<ScrollToTop />` at the bottom of your return function (for a11y reasons):

```js
import ScrollToTop from "react-scroll-to-top";

function CoolPage() {
  return (
    <div>
      <h1>Hello, world!</h1>
      <div style={{ marginTop: "150vh" }} />
      <ScrollToTop smooth />
    </div>
  );
}
```

## Props

| Prop      | Type    | Description                                                                          | Default       |
| --------- | ------- | ------------------------------------------------------------------------------------ | ------------- |
| smooth    | boolean | Whether to use smooth scrolling\*                                                    | false         |
| top       | number  | Height after page scroll to be visible                                               | 20            |
| color     | string  | The SVG icon fill color                                                              | "black"       |
| svgPath   | string  | The SVG icon path d attribute                                                        | An arrow path |
| width     | string  | The SVG icon width                                                                   | "28"          |
| height    | string  | The SVG icon height                                                                  | "28"          |
| viewBox   | string  | The SVG icon viewBox attribute                                                       | "0 0 256 256" |
| component | any     | Component to override SVG icon. See examples                                         |               |
| style     | Object  | Object to add/override styling                                                       |               |
| className | string  | Classname to add/override styling (note, `!important` for overrides might be needed) |               |

Smooth scrolling uses a newer `window.scrollTo` implementation.\
[Check out its support in browsers at MDN web docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo).

## Examples

[With custom SVG path](https://codesandbox.io/s/react-scroll-to-top-svg-path-y2ztc?file=/src/App.js)  
[With custom SVG component](https://codesandbox.io/s/react-scroll-to-top-custom-svg-or74g?file=/src/App.js)  
[With custom DOM element](https://codesandbox.io/s/react-scroll-to-top-custom-dom-element-y7j0f?file=/src/App.js)

## Types

Written in TypeScript, no need for @types installation

---
_Source: https://npm.io/package/react-scroll-to-top · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
