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.
// 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 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.
.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; }| Property | Chrome | Firefox | Safari |
|---|---|---|---|
scrollbar-width | 121 | 64 | 18.2 |
scrollbar-color | 121 | 64 | 26.2 |
scrollbar-gutter | 94 | 97 | 18.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.thin is the only size: its pixels, and the thumb's shape, are the engine's.::-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.
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; } }| Feature | Chrome | Firefox | Safari |
|---|---|---|---|
Scroll-driven animations (animation-timeline: scroll()) | 115 | 159 | 26 |
@property | 85 | 128 | 16.4 |
mask-image (unprefixed) | 120 | 53 | 15.4 |
@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.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.prefers-reduced-motion needs nothing here.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>.scroll-area:focus-visible { outline: none; }
.scroll-frame:has(> .scroll-area:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }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.tabindex when it overflows.What a native scroller still cannot do:
What a drawn scrollbar costs:
div thumb is a background colour that disappears);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.