FUNSTACK UI

HomeWhyGetting startedConceptsComponentsRoadmap
GitHub

FUNSTACK UI is in beta. Part of the FUNSTACK family with FUNSTACK Router and FUNSTACK Static, which build this site.

Introduction

  • Why FUNSTACK UI
  • Overview
  • Getting started

Concepts

  • Action props
  • Pending & optimistic state
  • Transitions & ViewTransition
  • Suspense
  • Browser-owned state
  • Server Components

Guides

  • Replacing the element (render)
  • Direction and locales
  • Experimental features
  • Next.js App Router
  • React Router framework mode
  • Content Security Policy
  • Using with AI agents

Components

  • Buttons
    • Button
    • Toggle
    • ToggleGroup
    • Toolbar
  • Disclosure
    • Tabs
    • Accordion
    • Collapsible
    • NavigationMenu
  • Overlays
    • Tooltip
    • HoverCard
    • Popover
    • Dialog
    • AlertDialog
    • Drawer
    • Menu
    • Context menu (Menu)
    • Menubar (Menu)
    • Toast
  • Forms
    • Field and Form
    • Checkbox
    • CheckboxGroup
    • RadioGroup
    • Switch
    • Select
    • Combobox
    • MultiSelect
    • Slider
    • NumberField
    • OTPField
    • TextField
  • Output
    • Progress
    • Meter
    • Avatar
  • Layout
    • Separator
    • Scroll areas (recipe)

Resources

  • Roadmap & changelog
  • GitHub ↗

Scroll areas

FUNSTACK UI has no ScrollArea part, by decision. A ScrollArea in other libraries hides the native scrollbar and draws one out of divs, because restyling a scrollbar once needed a different hack per engine. Today the standard properties work in all three engines, the fades at the edges are a scroll-driven animation, and the one gap a native scroller still has (keyboard access in Safari) is an attribute. This page is the recipe: plain CSS and HTML, no JavaScript, no part.

Release notes

  • Invoices can be exported as CSV.
  • The search box remembers your last five queries.
  • Fixed: dates in the calendar view used the wrong week start.
  • Team owners can transfer a project to another team.
  • The mobile layout keeps the toolbar visible while scrolling.
  • Fixed: a long project name no longer overlaps the menu.
  • Comments can be edited for ten minutes after posting.
  • Keyboard shortcuts are listed under Help.
  • Fixed: the dark theme used a light scrollbar in the sidebar.
  • Archived projects are hidden from the dashboard.
  • Uploads show their progress in the status bar.
  • Fixed: pasting a link into a comment kept its formatting.

Pages

  • Getting started
  • Action props
  • Pending & optimistic state
  • Transitions & ViewTransition
  • Suspense
  • Browser-owned state
  • Server Components
  • Replacing the element
  • Experimental features
  • Content Security Policy
Show code
ScrollAreaNotes.tsx
// No "use client": a Server Component, and there is no FUNSTACK UI part in it. Two native
// scrollers styled by scroll-area.css. The release notes have no focusable content, so the
// scroller is a Tab stop itself (tabindex="0", a role and a name): without it Safari gives the
// keyboard no way to scroll them. The links list needs none of that: Tab reaches the links, and
// the browser scrolls each into view.
// A pretend product's changelog.
const notes = [
  "Invoices can be exported as CSV.",
  "The search box remembers your last five queries.",
  "Fixed: dates in the calendar view used the wrong week start.",
  "Team owners can transfer a project to another team.",
  "The mobile layout keeps the toolbar visible while scrolling.",
  "Fixed: a long project name no longer overlaps the menu.",
  "Comments can be edited for ten minutes after posting.",
  "Keyboard shortcuts are listed under Help.",
  "Fixed: the dark theme used a light scrollbar in the sidebar.",
  "Archived projects are hidden from the dashboard.",
  "Uploads show their progress in the status bar.",
  "Fixed: pasting a link into a comment kept its formatting.",
];

const pages = [
  "Getting started",
  "Action props",
  "Pending & optimistic state",
  "Transitions & ViewTransition",
  "Suspense",
  "Browser-owned state",
  "Server Components",
  "Replacing the element",
  "Experimental features",
  "Content Security Policy",
];

export function ScrollAreaNotes() {
  return (
    <div className="demo-scroll-area-row">
      <section className="demo-scroll-area-frame" aria-labelledby="demo-scroll-notes-title">
        <h4 id="demo-scroll-notes-title">Release notes</h4>
        <div
          className="demo-scroll-area demo-scroll-fade"
          tabIndex={0}
          role="region"
          aria-label="Release notes, scrollable"
        >
          <ul className="demo-scroll-area-list">
            {notes.map((note) => (
              <li key={note}>{note}</li>
            ))}
          </ul>
        </div>
      </section>
      <nav className="demo-scroll-area-frame" aria-labelledby="demo-scroll-pages-title">
        <h4 id="demo-scroll-pages-title">Pages</h4>
        <div className="demo-scroll-area demo-scroll-fade">
          <ul className="demo-scroll-area-list">
            {pages.map((page) => (
              <li key={page}>
                <a href="#keyboard">{page}</a>
              </li>
            ))}
          </ul>
        </div>
      </nav>
    </div>
  );
}
scroll-area.css
/* Scroll areas: a native scroller, styled with the standard scrollbar properties, with edge
   fades driven by a scroll timeline (no script). Run in Chromium, Firefox and WebKit by
   packages/ui/src/__tests__/scroll-area-recipe.browser.test.tsx, which reads this file. */

.demo-scroll-area {
  max-block-size: 12rem;
  overflow: auto;
  /* auto | thin | none. The thumb's shape and exact width stay the engine's. */
  scrollbar-width: thin;
  /* thumb, then track. */
  scrollbar-color: var(--color-border) transparent;
  /* Space for the bar even before the content overflows: no shift when it starts to. */
  scrollbar-gutter: stable;
  /* Reaching an end does not scroll the page behind. */
  overscroll-behavior: contain;
}
.demo-scroll-area:hover,
.demo-scroll-area:focus-visible {
  scrollbar-color: var(--color-text-secondary) transparent;
}

/* Edge fades. The two lengths are 0 unless the timeline moves them: when nothing overflows the
   timeline is inactive and no fade is drawn. Each fade grows over the first (last) 2rem of
   scrolling, whatever the length of the content. Behind @supports: an engine without scroll
   timelines would run the animations once on the document clock and keep their end values,
   a fade over the top of the content for ever. */
@property --scroll-fade-start {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@property --scroll-fade-end {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
@supports (animation-timeline: scroll()) {
  .demo-scroll-fade {
    mask-image: linear-gradient(
      to bottom,
      transparent,
      #000 var(--scroll-fade-start),
      #000 calc(100% - var(--scroll-fade-end)),
      transparent
    );
    /* The shorthand resets the timeline, so the timeline and the ranges come after it. */
    animation:
      scroll-fade-start linear both,
      scroll-fade-end linear both;
    animation-timeline: scroll(self), scroll(self);
    animation-range:
      0 2rem,
      calc(100% - 2rem) 100%;
  }
}
@keyframes scroll-fade-start {
  from {
    --scroll-fade-start: 0px;
  }
  to {
    --scroll-fade-start: 2rem;
  }
}
@keyframes scroll-fade-end {
  from {
    --scroll-fade-end: 2rem;
  }
  to {
    --scroll-fade-end: 0px;
  }
}

/* The demo's content. */
.demo-scroll-area-list {
  margin: 0;
  padding: 0.5rem 0.75rem;
  list-style: none;
  display: grid;
  gap: 0.5rem;
}
.demo-scroll-area-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 16rem));
  gap: 1rem;
}
.demo-scroll-area-frame {
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
}
.demo-scroll-area-frame h4 {
  margin: 0;
  padding: 0.5rem 0.75rem;
  border-block-end: 1px solid var(--color-border);
  font-size: 0.875rem;
}
/* The focus ring goes on the frame, not on the scroller: the fade mask would fade the
   scroller's own outline away at an edge with content beyond it. */
.demo-scroll-area:focus-visible {
  outline: none;
}
.demo-scroll-area-frame:has(> .demo-scroll-area:focus-visible) {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

This example is a Server Component with no library code in it. Scroll either list: the fade at an edge appears once there is content beyond it.

The scrollbar

.scroll-area {
  overflow: auto;
  scrollbar-width: thin;                      /* auto | thin | none */
  scrollbar-color: var(--thumb) transparent;  /* thumb, then track */
  scrollbar-gutter: stable;                   /* space for the bar before the content overflows */
  overscroll-behavior: contain;               /* reaching an end does not scroll the page */
}
.scroll-area:hover,
.scroll-area:focus-visible { scrollbar-color: var(--thumb-strong) transparent; }
PropertyChromeFirefoxSafari
scrollbar-width1216418.2
scrollbar-color1216426.2
scrollbar-gutter949718.2
  • scrollbar-gutter: stable reserves the bar's space where scrollbars take space (classic scrollbars on Windows and most Linux desktops), so the content does not shift when it starts to overflow. Where scrollbars overlay the content (macOS by default, mobile) it reserves nothing.
  • The user's settings keep working: "always show scroll bars", the system scrollbar size, forced colours. A drawn bar loses all three.
  • thin is the only size: its pixels, and the thumb's shape, are the engine's.

A rounded thumb in Chromium and desktop Safari

::-webkit-scrollbar and its relatives still exist in Chromium and desktop Safari (not in Firefox; iOS honours only display: none), and give the thumb a radius and an inset. Chromium ignores them as soon as scrollbar-width or scrollbar-color is not auto, so choose one or the other per engine:

.scroll-area::-webkit-scrollbar { inline-size: 10px; block-size: 10px; }
.scroll-area::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 5px; background: var(--thumb) padding-box; }

/* Firefox, and any engine without the pseudo-elements. */
@supports not selector(::-webkit-scrollbar) {
  .scroll-area { scrollbar-width: thin; scrollbar-color: var(--thumb) transparent; }
}

The pseudo-elements are non-standard: forced colours and the user's scrollbar settings do not reach a thumb drawn with them either. iOS Safari matches the selector (so the @supports not selector(…) block does not apply there) but honours only display: none on it, so iOS gets neither the drawn thumb nor the standard properties: its overlay scrollbar stays the system's. If you want scrollbar-color on iOS, use the standard properties everywhere instead.

Edge fades

A fade at an edge that has more content beyond it, with no script: a scroll-driven animation moves two registered lengths that a mask gradient uses. When nothing overflows the timeline is inactive, the lengths keep their initial 0px, and no fade is drawn. Each fade grows over the first (and last) 2rem of scrolling, whatever the length of the content.

@property --scroll-fade-start { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --scroll-fade-end   { syntax: "<length>"; inherits: false; initial-value: 0px; }

@supports (animation-timeline: scroll()) {
  .scroll-fade {
    mask-image: linear-gradient(to bottom,
      transparent, #000 var(--scroll-fade-start),
      #000 calc(100% - var(--scroll-fade-end)), transparent);
    /* The shorthand resets the timeline: the timeline and the ranges come after it. */
    animation: scroll-fade-start linear both, scroll-fade-end linear both;
    animation-timeline: scroll(self), scroll(self);
    animation-range: 0 2rem, calc(100% - 2rem) 100%;
  }
}
@keyframes scroll-fade-start { from { --scroll-fade-start: 0px; } to { --scroll-fade-start: 2rem; } }
@keyframes scroll-fade-end   { from { --scroll-fade-end: 2rem; } to { --scroll-fade-end: 0px; } }
FeatureChromeFirefoxSafari
Scroll-driven animations (animation-timeline: scroll())11515926
@property8512816.4
mask-image (unprefixed)1205315.4
  • Keep the @supports. In an engine without scroll timelines the animations would run once on the document clock and keep their end values: a permanent fade over the top of the content.
  • The mask also fades the ends of a classic scrollbar, which is part of the masked box. If that matters, put the scroller inside a wrapper and draw the fades as overlays in the wrapper's background colour, driven by a named timeline (scroll-timeline on the scroller, timeline-scope on the wrapper; timeline-scope is Chrome 116, Firefox 159, Safari 26). That variant is a sketch: the browser test below does not run it.
  • The fade is a mask, not motion: prefers-reduced-motion needs nothing here.

Keyboard access

A keyboard user scrolls a scroller by focusing something inside it. When the content has nothing focusable (text, images), Chrome (since 132, per the update note in Chrome's Keyboard focusable scrollers post: first announced for 130, then pushed back) and Firefox make the scroller itself a Tab stop; Safari does not (WebKit bug 277290), so there the content is out of reach. Make such a scroller focusable, and give it a role and a name so that the Tab stop is announced as something:

<!-- Only when the content has nothing focusable. -->
<div class="scroll-area" tabindex="0" role="region" aria-label="Release notes">…</div>
  • Once focused, the arrow keys and Page Up / Page Down scroll it, in every engine (the browser's own scrolling keys; no script).
  • Give it a visible focus ring, but not on the scroller itself when it has the edge fades: the mask fades its own outline away at an edge with content beyond it. Draw the ring on a frame around it instead:
    .scroll-area:focus-visible { outline: none; }
    .scroll-frame:has(> .scroll-area:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
  • Do not add it when the content has links, buttons or fields: Tab reaches them and the browser scrolls each into view, and the extra Tab stop is noise.
  • role="region" with a name makes it a landmark. For a scroller that is a minor part of the page, role="group" with the same name avoids adding to the landmark list.
  • Whether the content has something focusable is a decision about your content, which you make better than a measuring script would. That is why this is not a part that adds tabindex when it overflows.

Why there is no part

What a native scroller still cannot do:

  • a thumb shape (radius, inset, exact thickness) in Firefox and on iOS;
  • an overlay scrollbar that takes no layout space on a platform whose scrollbars are classic, or one that hides until hover there.

What a drawn scrollbar costs:

  • the user's settings stop applying ("always show scroll bars", scrollbar size, forced colours, where a div thumb is a background colour that disappears);
  • a small pointer target unless you size it, and track clicks and drag behaviour that are reimplemented, never quite native;
  • script on every scroll and resize to place and size the thumb;
  • nothing for assistive technology: every library that draws one hides it from it.

And there is nothing asynchronous in it: no state the library would own, no action, nothing pending. If you need a drawn bar anyway, a dedicated scrollbar library is a better home for it than a headless kit.

Checked in three engines

The stylesheet of the example above is run by a browser test in Chromium, Firefox and WebKit (scroll-area-recipe.browser.test.tsx in the repository): the computed scrollbar properties, a gutter that is reserved before the content overflows where the bar takes space, the fade lengths at the top, in the middle and at the bottom, no fade without overflow, no fade at all in an engine without scroll timelines, the focusable region scrolled with the arrow keys and Page Down, and its focus ring on the frame. The Firefox the test runs (Playwright's build, 157) hides every scrollbar and predates scroll timelines, so there it checks the no-gutter and no-fade branches; the fade branch was run in it once with the feature's preference on. The ::-webkit-scrollbar and overlay variants above are not run.