Getting startedComponentsDesign tokensThemingTheme synthesizerFrameworksAccessibilityUtilitiesServer renderingBrowser supportContributingChangelogApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip
ARC UIARC Radiant Components
v4.9DocsComponentsTokensSynthesizer
Getting startedFrameworksServer renderingDesign tokensThemingTheme synthesizerTypographyUtilitiesAll componentsAccessibilityBrowser supportChangelogContributingStatsApp ShellAspect GridAuth ShellCenterContainerDashboard GridFloat BarInsetMasonryPage HeaderPage LayoutResizableResponsive SwitcherSectionSettings LayoutSplit PaneStatus BarStickyToolbarAnchor NavBottom NavBreadcrumbBreadcrumb MenuCommand BarDrawerFooterLinkMenubarNavigation MenuPage IndicatorPaginationRailScroll IndicatorScroll SpyScroll To TopSidebarSkip LinkStepper NavTabsTop BarTree ViewAccordionAspect RatioAvatarAvatar GroupCardCarouselCollapsibleColor SwatchCTA BannerDividerEmpty StateFeature CardIconImageImage CompareImage HotspotsInfinite ScrollLightboxMarqueeQR CodeScroll AreaSkeletonSpinnerStackVideoVirtual ListActivity HeatmapAnimated NumberBadgeBar ListChartClockComparisonCountdown TimerData GridDescription ListDiffGaugeJSON TreeKanbanLevel MeterListMeterSparklineStatStepperTagTimelineUptimeValue CardWaveformBlockquoteCode BlockCode GroupGradient TextHighlightKbdKeyboard MapMarkdownNumber FormatProseTerminalTextTime AgoTruncateTypewriterButtonButton GroupCalendarCheckboxChipColor PickerComboboxCopy ButtonDate PickerDate Range PickerField ListFieldsetFile UploadFormHotkeyIcon ButtonImage CropperInline EditInputInput GroupKnobLabelMasked InputMulti SelectNumber InputPassword InputPin InputRadio GroupRange SliderRatingSearchSegmented ControlSelectSignature PadSliderSortable ListSwitch GroupTag InputTextareaTheme ToggleTime PickerToggleTransfer ListTree SelectAlertAnnouncementBannerCommand PaletteConfirmConnection StatusContext MenuConversationDialogDropdown MenuHover CardLoading OverlayNotification PanelPopoverProgressSheetToastTooltip

Scroll Spy

An "On this page" table of contents that highlights the section you're reading.

ComponentsScroll Spy
navigationinteractive
<arc-scroll-spy>

Overview

ScrollSpy builds a table of contents from `<arc-spy-link>` children and marks the entry for the section you're reading. Put it in a sticky sidebar or aside next to long content. Each link's `target` is the `id` of a section, and its text is the label. ScrollSpy hides the links you write and renders its own list under an "On this page" heading. Clicking the heading scrolls back to the top. The current section is the last one whose top has scrolled past `offset` pixels from the top of the viewport (80 by default). Raise `offset` to clear a taller sticky header. When the page reaches the bottom, the last section counts as current even if it's too short to reach that line. ScrollSpy listens for scroll events on the whole document in the capture phase, so sections inside a scrolling container are tracked as well as ones in the window. The current link gets `aria-current="location"` and the accent background, and the component fires `arc-change` with `{ value }` set to the section id when scrolling changes the current section. Clicking a link marks it current without firing `arc-change`, scrolls its section into view, smoothly unless the reader has asked for reduced motion, and writes `#id` to the URL with `history.replaceState`.

Guidelines

Do

  • Give every section a unique `id` that matches a spy link's `target`
  • Set `offset` to the height of your sticky header or TopBar
  • Listen for `arc-change` to follow the section being read as the reader scrolls
  • Keep link labels short, matching or abbreviating the section headings

Don't

  • Don't use it for site navigation. It only tracks sections on the current page
  • Don't forget to import `arc-spy-link`. ScrollSpy reads its links from it
  • Don't give it more than 10 to 12 links. A longer list is hard to scan

Features

  • `level` on a spy link indents it and sets it in a smaller font, for nested headings
  • A link whose `target` matches no element on the page still shows in the list but is never marked current

Preview

Overview Installation Usage API reference Examples

Usage

This component needs JavaScript. Use the Web Component or a framework wrapper.

<arc-scroll-spy>
  <arc-spy-link target="section-1">Section 1</arc-spy-link>
  <arc-spy-link target="section-2">Section 2</arc-spy-link>
</arc-scroll-spy>

API

ringRadiusnumber6
Ring geometry. r drives the dasharray, so the two cannot drift apart.
activestring''
The id of the currently active section. Reflects to an attribute and updates automatically as the user scrolls.
offsetnumber80
Pixel distance from the top of the viewport at which a section counts as current. Increase it to account for taller sticky headers.
progress'none' | 'ring' | 'read' | 'both''none'
How the reader's position through the document is shown. ring draws a progress arc beside the heading; read recedes the entries already scrolled past; both does each. Defaults to none, and an unrecognized value lands there too.

Events

arc-change
Fired when the active spy target changes during scroll

See also