Back to Top

A floating button that scrolls the page back to the top.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrBackTop } from 'ngwr/back-top';

@Component({ imports: [WrBackTop] })
export class MyComponent {}

Demo

The button appears after visibilityThreshold pixels of scroll.

<wr-back-top visibilityThreshold="400" [offset]="80" />
Top of sandbox — scroll the page to push past the 400px threshold.Mid-section — by now the back-to-top button should be pinned in the bottom-right.Bottom of sandbox — click the floating button to scroll back up.

Your own glyph

Projected content replaces the arrow.

<!-- Register the icon with provideWrIcons(). -->
<wr-back-top>
  <wr-icon name="arrow-up" />
</wr-back-top>

API

NameDescriptionTypeDefault
visibilityThresholdShow the button once window.scrollY exceeds this many pixels.number400
offsetPixel offset subtracted from the scroll target — for sticky headers.number0
ariaLabelAccessible label for the button. Falls back to backTop.label, then 'Back to top'.string | nullnull

Dependencies

Built onWrScroll

See also