Scroll To Top
A floating button that shows up once you've scrolled down and takes you back to the top of the page.
<arc-scroll-to-top>Overview
ScrollToTop is a round, fixed-position button with an up chevron. It fades and slides in once the window has scrolled past threshold pixels (300 by default), and clicking it scrolls the window back to the top. It watches the window with its own passive scroll listener, throttled to one check per animation frame, so all you do is put the element on the page.
The button is labelled "Scroll to top". With prefers-reduced-motion set, the scroll is an instant jump and the fade has no transition.
Guidelines
Do
- Put one at the page level, outside any scrolling container. It only listens to the window
- Raise or lower `threshold` to suit how long the page is
- Pair it with ScrollSpy on long docs pages
Don't
- Don't put more than one on a page
- Don't set `threshold` so low that the button shows up after a flick of the wheel
Features
- Sits in the bottom-right corner by default. `position="bottom-left"` moves it
- `offset` sets the distance from the edges and takes any CSS length
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<!-- Place once at the page level -->
<arc-scroll-to-top></arc-scroll-to-top>
<!-- Custom threshold and position -->
<arc-scroll-to-top threshold="500" position="bottom-left"></arc-scroll-to-top>import { ScrollToTop } from '@arclux/arc-ui-react';
export function Layout({ children }) {
return (
<>
{children}
<ScrollToTop threshold={400} />
</>
);
}<script setup>
import { ScrollToTop } from '@arclux/arc-ui-vue';
</script>
<template>
<main>
<slot />
</main>
<ScrollToTop />
</template><script>
import { ScrollToTop } from '@arclux/arc-ui-svelte';
</script>
<main>
<slot />
</main>
<ScrollToTop />import { Component } from '@angular/core';
import { ScrollToTop } from '@arclux/arc-ui-angular';
@Component({
imports: [ScrollToTop],
template: `
<main>
<ng-content></ng-content>
</main>
<arc-scroll-to-top></arc-scroll-to-top>
`,
})
export class LayoutComponent {}import { ScrollToTop } from '@arclux/arc-ui-solid';
export function Layout(props) {
return (
<>
{props.children}
<ScrollToTop />
</>
);
}import { ScrollToTop } from '@arclux/arc-ui-preact';
export function Layout({ children }) {
return (
<>
{children}
<ScrollToTop />
</>
);
}API
thresholdnumber300- Scroll distance in pixels before the button becomes visible.
offsetstring'var(--space-lg)'- Distance from viewport edges. Accepts any CSS length value.
smoothbooleantrue- Use smooth scrolling animation. Falls back to instant when prefers-reduced-motion is set.
position'bottom-right' | 'bottom-left''bottom-right'- Corner placement.