Skip to content
# ScrollToTop **Also known as:** BackToTop, GoToTop ## Description BitScrollToTop is the button that takes the reader back to the top of a long page or pane: in the flow of the page, as the "back to top" of a footer, or floating in a corner of the screen and revealed once the reader has scrolled far enough away from the top. It scrolls the page, or the pane it sits in or names, smoothly unless the reader has asked for less motion, and moves the keyboard focus to the top along with the view. ## Parameters | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Classes | `BitScrollToTopClassStyles?` | null | Custom CSS classes for the different parts of the scroll to top button. | | Float | `bool` | false | Floats the button over the content, pinned to a corner or an edge of the viewport (FloatPosition). Left unset, the button sits in the flow of the page where it is written. | | FloatAbsolute | `bool` | false | Floats the button over the content, pinned to a corner or an edge of its nearest positioned ancestor rather than of the viewport. Takes precedence over Float. | | FloatOffset | `string?` | null | The inset of a floating button from the edge it is pinned to: any CSS length (1rem, 5%, a calc()), or a bare number, which is read as pixels. It wins over --bit-ScrollToTop-float-offset. | | FloatPosition | `BitPosition?` | null | Where a floating button is pinned. Defaults to BottomEnd: the bottom right corner, and the bottom left one in a right-to-left page. | | Icon | `BitIconInfo?` | null | The icon of the button, provided as custom CSS classes of an external icon library. Takes precedence over IconName when both are set. | | IconName | `string?` | null | The name of the icon of the button, from the built-in Fluent UI icons. A button with no Text shows an arrow pointing up (Up) when no icon is given, and one with a text shows no icon unless one is given. | | RevealOffset | `int?` | null | How far (in pixels) the scroll has to travel from the top before the button is revealed. Within it the button is hidden - out of the view, the tab order and the accessibility tree - from the first render on. When not set, the button is always shown. | | ScrollTarget | `string?` | null | The CSS selector of the element whose scrolling the button scrolls back to its top, and reveals itself by. By default the button walks up from itself to the box that scrolls it - the page or a pane it sits in; a selector that matches nothing falls back to that walk. | | Smooth | `bool` | true | Scrolls back to the top smoothly rather than in a single jump. It collapses to a jump under a reduced-motion preference, unless ForceAnimation is set. | | Styles | `BitScrollToTopClassStyles?` | null | Custom CSS styles for the different parts of the scroll to top button. | | Text | `string?` | null | The text of the button, shown beside its icon, which also names the button. When not set, the button shows its icon alone and is named by the AriaLabel, or else by BitStrings.ScrollToTop ("Scroll to top"). | | AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. | | Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. | | Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. | | Disabled | `bool` | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. | | ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. | | HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. | | Id | `string?` | null | Gets or sets the unique identifier for the component's root element. | | Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. | | TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. | | Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. | ## Public Members | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. | | RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. | ## Enums ### BitPosition Enum | Name | Value | Description | | :--- | :--- | :---------- | | TopLeft | 0 | The top left corner, in both reading directions. | | TopCenter | 1 | The top edge, centered horizontally. | | TopRight | 2 | The top right corner, in both reading directions. | | TopStart | 3 | The top edge, on the side the reading direction starts from. | | TopEnd | 4 | The top edge, on the side the reading direction ends at. | | CenterLeft | 5 | The left edge, centered vertically, in both reading directions. | | Center | 6 | Centered both ways. | | CenterRight | 7 | The right edge, centered vertically, in both reading directions. | | CenterStart | 8 | Centered vertically, on the side the reading direction starts from. | | CenterEnd | 9 | Centered vertically, on the side the reading direction ends at. | | BottomLeft | 10 | The bottom left corner, in both reading directions. | | BottomCenter | 11 | The bottom edge, centered horizontally. | | BottomRight | 12 | The bottom right corner, in both reading directions. | | BottomStart | 13 | The bottom edge, on the side the reading direction starts from. | | BottomEnd | 14 | The bottom edge, on the side the reading direction ends at. | ### BitVisibility Enum | Name | Value | Description | | :--- | :--- | :---------- | | Visible | 0 | The content of the component is visible. | | Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). | | Collapsed | 2 | The component is hidden (display:none). | ### BitDir Enum | Name | Value | Description | | :--- | :--- | :---------- | | Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). | | Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). | | Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. | ## Sub Classes ### BitScrollToTopClassStyles Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Root | `string?` | null | Custom CSS classes/styles for the root element (the button) of the BitScrollToTop. | | Icon | `string?` | null | Custom CSS classes/styles for the icon of the BitScrollToTop. | | Text | `string?` | null | Custom CSS classes/styles for the text of the BitScrollToTop. | ### BitIconInfo Properties | Name | Type | Default Value | Description | | :--- | :--- | :------------ | :---------- | | Name | `string?` | null | Gets or sets the name of the icon. | | BaseClass | `string?` | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. | | Prefix | `string?` | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. | ## CSS Variables Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves. | Name | Default Value | Description | | :--- | :------------ | :---------- | | `--bit-ScrollToTop-color` | --bit-clr-pri-text | Foreground (text and icon) at rest. | | `--bit-ScrollToTop-background` | --bit-clr-pri | Background at rest. | | `--bit-ScrollToTop-border-color` | the background at rest | Border color at rest; on hover and while pressed the border follows the background. | | `--bit-ScrollToTop-border-width` | --bit-shp-border-width | Thickness of the border. | | `--bit-ScrollToTop-hover-color` | the foreground at rest | Foreground on hover. | | `--bit-ScrollToTop-hover-background` | --bit-clr-pri-hover | Background on hover. | | `--bit-ScrollToTop-active-color` | the foreground on hover | Foreground while pressed. | | `--bit-ScrollToTop-active-background` | --bit-clr-pri-active | Background while pressed. | | `--bit-ScrollToTop-disabled-color` | --bit-clr-pri-dis-text | Foreground when disabled. | | `--bit-ScrollToTop-disabled-background` | --bit-clr-pri-dis | Background and border when disabled. | | `--bit-ScrollToTop-focus-color` | --bit-clr-pri-focus | Focus ring color. | | `--bit-ScrollToTop-radius` | --bit-shp-radius-button | Corner radius of the box and its focus ring. | | `--bit-ScrollToTop-size` | --bit-siz-ctrl-lg | Height of the box, and the width of an icon-only one. | | `--bit-ScrollToTop-padding` | 0 --bit-siz-ctrl-pad-x-md | Padding of a button with a text. | | `--bit-ScrollToTop-gap` | spacing(1) | Room between the icon and the text. | | `--bit-ScrollToTop-font-size` | --bit-tpg-fs-sm | Size of the text. | | `--bit-ScrollToTop-icon-size` | --bit-siz-icon-md | Size of the icon. | | `--bit-ScrollToTop-float-offset` | spacing(2) | Inset of a floating button from the edge it is pinned to. The FloatOffset parameter wins over it. | | `--bit-ScrollToTop-float-shadow` | --bit-shd-card | Elevation of a floating button, which lifts it off the content it sits over. The focus ring is a shadow too and replaces it while the button is focused. | ## Examples \n**Basic**: ```razor ``` \n**Icon**: ```razor ``` \n**Float & RevealOffset**: ```razor ``` \n**ScrollTarget**: ```razor
@for (var i = 1; i <= 30; i++) {
Line @i of a pane long enough to scroll.
}
``` \n**Smooth**: ```razor
@for (var i = 1; i <= 30; i++) {
Line @i of a pane long enough to scroll.
}
``` \n**External Icons**: ```razor ``` \n**Style & Class**: ```razor ``` \n**RTL**: ```razor
```