When to use it#
- Use it around content that can’t wrap without losing its meaning: a wide table from your content system, or a long line of code. Let everything else wrap, so the page doesn’t scroll sideways at 320 pixels wide (1.4.10 Reflow).
- When everything fits it is a plain
<div>. While it scrolls it is a named region (a part of the page that a screen reader, software that reads the screen aloud, can list so users jump to it) and a Tab stop (a place the Tab key stops at). Withregion="always"it is a named region even when it fits, but it is a Tab stop only while it scrolls. - Name it and say what is inside: the name is what a screen reader reads.
- Not for a table you build with Table: Table has its own scroll region. Not for a long page: let the page scroll.
Example#
| Permit | Category | Applicant | Processing time | Fee | Appeal period | Decision by | Contact |
|---|---|---|---|---|---|---|---|
| Building permit | Housing | Property owner | 10 weeks | 12,400 kr | 3 weeks | Building committee | building@kvirn.example |
| Demolition permit | Housing | Property owner | 6 weeks | 4,200 kr | 3 weeks | Building committee | building@kvirn.example |
| Change of use | Commercial | Business owner | 8 weeks | 9,800 kr | 3 weeks | Building committee | building@kvirn.example |
| Sign permit | Commercial | Business owner | 4 weeks | 1,900 kr | 3 weeks | Planning office | planning@kvirn.example |
| Outdoor serving | Hospitality | Business owner | 5 weeks | 2,700 kr | 3 weeks | Licensing office | licensing@kvirn.example |
| Event permit | Culture | Organiser | 3 weeks | 1,200 kr | 2 weeks | Licensing office | licensing@kvirn.example |
import { ScrollArea } from '@kvirn-ui/react'
import { useScrollAreaTexts } from './texts.ts'
export function DefaultScrollArea() {
const { texts } = useScrollAreaTexts()
return (
<ScrollArea aria-label={texts.feesLabel}>
<table className="kv-table">
<thead>
<tr>
{texts.headers.map((header) => (
<th key={header} scope="col">
{header}
</th>
))}
</tr>
</thead>
<tbody>
{texts.rows.map((row) => (
<tr key={row[0]}>
{row.map((cell, index) =>
index === 0 ? (
<th key={cell} scope="row">
{cell}
</th>
) : (
<td key={texts.headers[index]}>{cell}</td>
),
)}
</tr>
))}
</tbody>
</table>
</ScrollArea>
)
}Information: Implement like this
The area sets no size. Add your own class with a height limit, such as className="permit-list", and it scrolls down as well as sideways.
.permit-list {
max-block-size: 20rem;
}Use cases#
A short fee list that fits
A short table fits, so nothing scrolls and the area is a plain div: no role, no name and no Tab stop. It becomes a named region by itself if the window narrows or the text grows.
| Event size | Fee |
|---|---|
| Small event | 600 kr |
| Medium event | 1,200 kr |
| Large event | 2,400 kr |
import { ScrollArea } from '@kvirn-ui/react'
import { useScrollAreaTexts } from './texts.ts'
export function Fits() {
const { texts } = useScrollAreaTexts()
return (
<ScrollArea aria-label={texts.shortLabel}>
<table className="kv-table">
<thead>
<tr>
{texts.shortHeaders.map((header) => (
<th key={header} scope="col">
{header}
</th>
))}
</tr>
</thead>
<tbody>
{texts.shortRows.map(([size, fee]) => (
<tr key={size}>
<th scope="row">{size}</th>
<td>{fee}</td>
</tr>
))}
</tbody>
</table>
</ScrollArea>
)
}A table people can jump to
Set region to always when a table matters enough that screen reader users should find it in their list of regions, even when it fits. It is still a Tab stop only while it scrolls.
| Event size | Fee |
|---|---|
| Small event | 600 kr |
| Medium event | 1,200 kr |
| Large event | 2,400 kr |
import { ScrollArea } from '@kvirn-ui/react'
import { useScrollAreaTexts } from './texts.ts'
export function AlwaysRegion() {
const { texts } = useScrollAreaTexts()
return (
<ScrollArea aria-label={texts.shortLabel} region="always">
<table className="kv-table">
<thead>
<tr>
{texts.shortHeaders.map((header) => (
<th key={header} scope="col">
{header}
</th>
))}
</tr>
</thead>
<tbody>
{texts.shortRows.map(([size, fee]) => (
<tr key={size}>
<th scope="row">{size}</th>
<td>{fee}</td>
</tr>
))}
</tbody>
</table>
</ScrollArea>
)
}Props in this example:
regionon ScrollArea
A code sample in an open-data guide
A long line of code keeps its meaning only when it isn’t wrapped. Let the area scroll sideways, and name it so people know what it holds.
curl "https://data.kvirn.example/api/permits?category=housing&year=2026&status=granted&format=json&sort=decision-date"import { ScrollArea } from '@kvirn-ui/react'
import { useScrollAreaTexts } from './texts.ts'
export function CodeSample() {
const { texts } = useScrollAreaTexts()
return (
<ScrollArea aria-label={texts.codeLabel}>
<pre>
<code>{texts.code}</code>
</pre>
</ScrollArea>
)
}A table in your own element
When the markup is yours, spread the props of the hook on the element that scrolls. Add the name only while isRegion is true, because a name on a plain div is not allowed.
| Permit | Category | Applicant | Processing time | Fee | Appeal period | Decision by | Contact |
|---|---|---|---|---|---|---|---|
| Building permit | Housing | Property owner | 10 weeks | 12,400 kr | 3 weeks | Building committee | building@kvirn.example |
| Demolition permit | Housing | Property owner | 6 weeks | 4,200 kr | 3 weeks | Building committee | building@kvirn.example |
| Change of use | Commercial | Business owner | 8 weeks | 9,800 kr | 3 weeks | Building committee | building@kvirn.example |
| Sign permit | Commercial | Business owner | 4 weeks | 1,900 kr | 3 weeks | Planning office | planning@kvirn.example |
| Outdoor serving | Hospitality | Business owner | 5 weeks | 2,700 kr | 3 weeks | Licensing office | licensing@kvirn.example |
| Event permit | Culture | Organiser | 3 weeks | 1,200 kr | 2 weeks | Licensing office | licensing@kvirn.example |
import { useScrollArea } from '@kvirn-ui/react'
import { useScrollAreaTexts } from './texts.ts'
export function OwnMarkup() {
const { texts } = useScrollAreaTexts()
const scrollArea = useScrollArea()
return (
<div
{...scrollArea.scrollAreaProps}
aria-label={scrollArea.isRegion ? texts.feesLabel : undefined}
>
<table className="kv-table">
<thead>
<tr>
{texts.headers.map((header) => (
<th key={header} scope="col">
{header}
</th>
))}
</tr>
</thead>
<tbody>
{texts.rows.map((row) => (
<tr key={row[0]}>
{row.map((cell, index) =>
index === 0 ? (
<th key={cell} scope="row">
{cell}
</th>
) : (
<td key={texts.headers[index]}>{cell}</td>
),
)}
</tr>
))}
</tbody>
</table>
</div>
)
}Props in this example:
scrollAreaPropson useScrollArea (result)isRegionon useScrollArea (result)
Accessibility#
What it does for you#
- APG pattern: none. A scrollable region with native scrolling: the `region` role and a Tab stop only while it scrolls, so a keyboard user can scroll it (2.1.1 Keyboard, A).
- Deviations: none. Native scrollbars only, never hidden or thinned; there is no
orientationprop, because the nativeoverflowalready scrolls whichever axis overflows. - Native elements used:
<div>(or<section>withas) that is arole="region"while it scrolls, or always withregion="always".
A ScrollArea holds content that may be wider or taller than its box, such as a wide table, a long code sample or a pasted block, and scrolls it with the browser's own scrollbars. While the content doesn't fit it is a named region you can Tab to and scroll with the arrow keys. When everything fits it is a plain <div>. Safari doesn't make a scrollable <div> a Tab stop by itself, which is why the area sets tabindex="0" while it scrolls.
| Part | Element / role | ARIA / state | Notes |
|---|---|---|---|
| ScrollArea | <div>, <div role="region"> while it scrolls or region="always" | role="region" only while the area is one: it overflows, or region="always". tabindex="0" and data-overflowing only while it overflows. Not a region (nothing overflows): no role, no name, no tabindex. | The part's class names are listed in the API reference. Name it with your own aria-labelledby or aria-label, applied only once it is a region. A region with no name: a development warning |
useScrollArea | the same attributes, for your own element | scrollAreaProps, isOverflowing, isRegion, element | Option region: 'overflow' (default) or 'always'. Spread scrollAreaProps on the element that scrolls |
It announces nothing.
What you need to do#
- Without the theme, set
overflow: auto(the default theme does it). The component sets no style, so an unstyled area doesn't scroll. - Name it with
aria-labelledby(a heading or caption) oraria-label, and say what is inside. A region without a name is read as an unlabelled landmark (4.1.2 Name, Role, Value, A). - Limit its height with CSS (
max-block-size) to scroll down as well as sideways. The component sets no size. - Keep the content reachable: controls inside keep their own Tab stops, so don't hide the scrollbars or turn off native scrolling.
- Show that the content continues. Add a short caption such as "The table scrolls sideways", or set a width that cuts a column in half. Sighted touch users on iOS, Android and macOS get no scrollbar until they scroll.
- Don't scroll the page's main content inside a nested area without a reason: a scroll area inside a scroll area is hard to use.
Warning: Don't forget
Name the area and say what is inside. Without a name a screen reader says only “region”, and the user can’t tell what it holds (4.1.2 Name, Role, Value).
Visual and modes#
- Focus indicator: the default theme draws a focus ring on the area (2.4.7 Focus Visible, AA; 2.4.11 Focus Not Obscured (Minimum), AA). In forced colours the ring uses the system's highlight colour.
- Target size: n/a, native scrollbars.
- forced-colors: the focus ring uses the system's highlight colour. Native scrollbars follow the system colours.
- reduced-motion: no motion.
- Reflow and zoom: the area scrolls its own content, so a wide table doesn't make the page scroll sideways at 320 px (1.4.10 Reflow, AA). The default theme keeps the area within the page width. If you restyle it, keep it within 320 CSS pixels.
- RTL: native: the scroll origin and the arrow keys flip.
Warning: Don't forget
If you restyle the area, keep its focus ring and its native scrollbars. Keyboard users need the ring to see where they are (2.4.7 Focus Visible).
Focus management#
- Initial focus: none. The area never moves focus.
- Trap: no. Tab always leaves the area.
- Restore to: n/a.
- The area stays a region and a Tab stop while it holds focus, even if the content stops overflowing (a wider window, zooming out): taking the role and the tab stop from the focused element would drop focus to the page. It lets go once focus leaves.
- Never obscured by: nothing. The theme draws a focus ring on the area, and a focused control inside it scrolls into view natively.
Allowed elements#
A tag outside the list changes the page's outline or semantics (1.3.1 Info and Relationships, A; 4.1.2 Name, Role, Value, A). as is a string, so it works from a Server Component.
| Part | `as` | Why |
|---|---|---|
| ScrollArea | div (default), section | A scroll container is a region while it scrolls, so section adds nothing but is harmless. No landmark element (nav, aside, main) and no list: the area holds content, it is not content. A value outside the list is a type error and, in JS, warns once in development and renders the default element. |
WCAG success criteria#
| SC | Name | How |
|---|---|---|
| 1.3.1 | Info and Relationships (A) | A named region only while it scrolls |
| 1.4.10 | Reflow (AA) | Content that is wider than the viewport scrolls inside the area |
| 2.1.1 | Keyboard (A) | A Tab stop while it scrolls, and the native scroll keys |
| 2.4.7 | Focus Visible (AA) | The area takes focus while it scrolls The theme draws the ring; the ring is checked by eye, and the forced-colours sweep checks it is drawn |
| 2.4.11 | Focus Not Obscured (Minimum) (AA) | The area adds no overlay, sticky part or custom scrollbar, so nothing of its own covers it. This is checked by eye |
| 4.1.2 | Name, Role, Value (A) | role="region" and a name from the consumer, with a development warning when it has none |
Keyboard#
- Focus
- native: the area is one Tab stop while it overflows, and scrolls with the browser's own keys
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
| Key | Where | What happens |
|---|---|---|
| Tab | before the area | Moves to the area when it overflows, and past it when nothing scrolls Test: scroll-area.test.tsx › Tab focuses the area when it overflows, scroll-area.test.tsx › Tab skips the area when nothing scrolls |
| Shift+Tab | after the area | Moves back to the area when it overflows, and to the element before it otherwise Test: scroll-area.test.tsx › Shift+Tab moves back to the area when it overflows |
| ArrowDown / ArrowUp | on the focused area | Scrolls the area down or up (native) Test: scroll-area.test.tsx › ArrowDown scrolls the focused area, scroll-area.test.tsx › ArrowUp scrolls the focused area back up |
| ArrowRight / ArrowLeft | on the focused area | Scrolls the area sideways (native, flips in RTL) Test: scroll-area.test.tsx › ArrowRight scrolls the focused area sideways, scroll-area.test.tsx › ArrowLeft scrolls the area sideways in right-to-left, scroll-area.test.tsx › ArrowRight scrolls the area sideways in right-to-left |
| PageDown / PageUp | on the focused area | Scrolls the area a page down or up (native) Test: scroll-area.test.tsx › PageDown scrolls the focused area a page, scroll-area.test.tsx › PageUp, Home and End scroll the focused area |
| Home / End | on the focused area | Scrolls to the start or the end (native) Test: scroll-area.test.tsx › PageUp, Home and End scroll the focused area |
| Space | on the focused area | Scrolls the area a page down (native) Test: scroll-area.test.tsx › Space scrolls the focused area a page |
| Escape and letters | on the focused area | Nothing. There is no type-ahead and no shortcut Test: scroll-area.test.tsx › Escape and letters do nothing |
Announcements#
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
| The content fits | the content only, no region | none | none |
| The content overflows | region, <name> | none | none |
region="always", the content fits | region, <name> | none | none |
| Tab onto the overflowing area | <name>, region | none | none |
API reference#
import { ScrollArea, useScrollArea } from '@kvirn-ui/react'ScrollArea
Renders <div>, which is a region only while it scrolls (or with region="always"). It takes every attribute of a <div> and passes ref to it. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
region | 'overflow' | 'always' | 'overflow' | overflow: a named region only while the content doesn’t fit. always: a named region whether it scrolls or not. It is a Tab stop only while it scrolls, in both. |
className | string | – | Your own classes. They join kv-scroll-region kv-scroll-area and never replace them, so the theme keeps styling the area. Use one to limit its height. |
as | 'div' | 'section' | 'div' | Changes the element. It is a region while it scrolls either way, so section adds nothing. No landmark element and no list. A string, so it works from a Server Component. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-scroll-region kv-scroll-area | always | The part classes. The default theme sets overflow, the focus ring and the rounded corners. |
role | region, while it scrolls or with region="always" | Not a region when everything fits: no role, no name. |
tabindex | 0, only while it overflows | Makes the area a Tab stop so a keyboard user can scroll it. Your own tabIndex wins. |
data-overflowing | present while the content doesn’t fit | The area scrolls. It stays while the area holds focus. |
aria-label | aria-labelledby | yours | Applied once the area is a region. A name on a plain <div> is not allowed. |
useScrollArea
Options
| Prop | Type | Default | Description |
|---|---|---|---|
region | 'overflow' | 'always' | 'overflow' | overflow: a named region only while the content doesn’t fit. always: a named region whether it scrolls or not. It is a Tab stop only while it scrolls, in both. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
scrollAreaProps | ScrollAreaPartProps | – | Spread on the element that scrolls: the classes, role, tabIndex, data-overflowing and a ref. Name it yourself with aria-labelledby or aria-label. |
isOverflowing | boolean | – | The content is wider or taller than the area. It stays true while the area holds focus. |
isRegion | boolean | – | The area has role="region" now: it overflows, or region is always. |
element | HTMLElement | null | – | The scroll element, once it is mounted. |
Testing#
The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.
| AT + browser + OS | Agent check | Human check | Result | Notes |
|---|---|---|---|---|
| Automated (re-runnable tests) | ||||
| axe, WCAG 2.2 A and AA, every story, 4 themes | pass | n/a | pass | scroll-area.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | scroll-area.test.tsx › content that fits is a plain div: no role, no name, no tabindex, no data-overflowing; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 8 rows, each names a test (scroll-area.test.tsx › Tab focuses the area when it overflows) |
| Focus order and management | pass | n/a | pass | scroll-area.test.tsx asserts focus (toHaveFocus); first rule: Tab focuses the area when it overflows |
| Display modes (forced colours, 320px reflow, text spacing, reduced motion) | pass | n/a | pass | the four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI |
| Core (required for beta) | ||||
| NVDA + Chrome + Windows | pending | pending | pending | |
| VoiceOver + Safari + iOS | pending | pending | pending | |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | pending | pending | pending | |
| TalkBack + Chrome + Android | pending | pending | pending | |
| VoiceOver + Safari + macOS | pending | pending | pending |
What to check#
- With content wider than the box, Tab to the area: it is announced as a region with its name.
- Arrow keys, Home, End and Page Down scroll it.
- Widen the window until the content fits: the region is gone and Tab skips it.
- At 400% zoom or 320px, only the area scrolls, not the page.
- In forced colours the area's focus ring is visible.