← All Components
<mth-back-to-top>
Floating scroll-to-top action button that reveals automatically after scrolling past threshold pixels.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-back-to-top>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/back-to-top"></script>
<mth-back-to-top threshold="300" smooth>Example</mth-back-to-top>import '@methane-ui/ui/back-to-top';
import '@methane-ui/react';
export function Example() {
return <mth-back-to-top threshold="300" smooth>Example</mth-back-to-top>;
}<script setup lang="ts">
import '@methane-ui/ui/back-to-top';
</script>
<template>
<mth-back-to-top threshold="300" smooth>Example</mth-back-to-top>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/back-to-top';
import { MthBackToTopDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthBackToTopDirective],
template: `<mth-back-to-top threshold="300" smooth>Example</mth-back-to-top>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/back-to-top';
import MthBackToTop from '@methane-ui/svelte/MthBackToTop.svelte';
</script>
<MthBackToTop threshold="300" smooth>Example</MthBackToTop>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
threshold | threshold | number | 300 | Vertical scroll offset in pixels before the button becomes visible. |
label | label | string | "" | Accessible button aria-label override. |
smooth | smooth | boolean | true | Uses smooth scroll behavior unless reduced motion is preferred. |
visible | visible | boolean | false | Reflected visibility state when threshold is exceeded or alwaysVisible is true. |
alwaysVisible | always-visible | boolean | false | Keeps the button visible regardless of scroll offset. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-scroll-top | { threshold: number } | Cancelable event dispatched just before scrolling to top. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| Enter | both | button focused | scrolls document or target container to top |
| Space | both | button focused | scrolls document or target container to top |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 2 APG keyboard transitions across LTR/RTL. | mth-back-to-top.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(visible). | Conformance suite |
| i18n | Routes 2 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |