When to use it#
- Use a section for a region of a page: a sidebar, a band of related content, a group of navigation links.
- Put a heading at the top, at the level the page’s outline needs. Make the section a landmark only for a region a user would want to jump to, because people who use a screen reader (software that reads the screen aloud) can jump from landmark to landmark.
- Keep the DOM order the same as the reading order: a sidebar that sits beside the main content comes after it in the code.
- Not for one thing in a region, such as a service or a news item: use a Card. A card on a section is fine, a section inside a card isn’t.
- Don’t render a section with no content: it still has padding and a surface.
Example#
News
Opening hours at the recycling centre change on 1 November.
import { Heading, Section } from '@kvirn-ui/react'
import { useSectionTexts } from './texts.ts'
export function DefaultSection() {
const { texts } = useSectionTexts()
return (
<Section className="kv-prose">
<Heading as="h3">{texts.news.heading}</Heading>
<p>{texts.news.text}</p>
</Section>
)
}Use cases#
A sidebar with contact details
Render the section as an <aside> for complementary content, such as contact details. Name it with aria-labelledby pointing at its heading, so it is in the screen reader’s list of landmarks.
import { Heading, Link, Section } from '@kvirn-ui/react'
import { useId } from 'react'
import { useSectionTexts } from './texts.ts'
export function Sidebar() {
const { texts } = useSectionTexts()
const headingId = useId()
return (
<Section as="aside" aria-labelledby={headingId} className="kv-section--padding-lg kv-prose">
<Heading as="h4" id={headingId}>
{texts.contact.heading}
</Heading>
<p>{texts.contact.text}</p>
<p>
<Link href="#">{texts.contact.link}</Link>
</p>
</Section>
)
}Props in this example:
Warning: Don't forget
Name every landmark with the heading it holds. A <section> without a name is not a landmark, so users can’t jump to it (4.1.2 Name, Role, Value). Keep landmarks few.
A sidebar of links to your cases
Render the section as a <nav> for a sidebar of links, and name it with aria-labelledby. Use a named navigation landmark only for the links that are the page’s navigation.
import { Heading, Link, Section } from '@kvirn-ui/react'
import { useId } from 'react'
import { useSectionTexts } from './texts.ts'
export function SectionNavigation() {
const { texts } = useSectionTexts()
const headingId = useId()
return (
<Section as="nav" aria-labelledby={headingId}>
<Heading as="h4" id={headingId}>
{texts.navigation.heading}
</Heading>
<ul>
<li>
<Link href="#">{texts.navigation.overview}</Link>
</li>
<li>
<Link href="#">{texts.navigation.open}</Link>
</li>
<li>
<Link href="#">{texts.navigation.closed}</Link>
</li>
</ul>
</Section>
)
}Props in this example:
ason Section
A waste-collection band with a card
Use canvas when a region should look like the page again, for example a band that holds a card. It is not a landmark: its heading shows it in the page outline.
Waste collection
Food waste and residual waste are collected every other week.
Your next collection
Tuesday at Main Street 12.
import { Card, Heading, Section } from '@kvirn-ui/react'
import { useSectionTexts } from './texts.ts'
export function Band() {
const { texts } = useSectionTexts()
return (
<Section className="kv-section--canvas">
<Heading as="h4">{texts.band.heading}</Heading>
<p>{texts.band.text}</p>
<Card.Root className="kv-prose">
<Heading as="h5">{texts.band.cardHeading}</Heading>
<p>{texts.band.cardText}</p>
</Card.Root>
</Section>
)
}Props in this example:
classNameon Section
Information: Did you know?
A card on a section is fine. A section inside a section is only for switching between the surface and canvas looks. Don’t put a section inside a card.
A guide in parts, as a list
Render each section as an <li> inside a <ul>when a page is a set of short parts that belong together. A screen reader announces it as a list. Give each part its own heading.
Who can apply
You live in the permit zone and your car is registered at your address.
What you need
Your registration number and a photo of the vehicle registration certificate.
What it costs
The permit costs 400 kronor a year. You pay when you apply.
import { Heading, Section } from '@kvirn-ui/react'
import { useSectionTexts } from './texts.ts'
export function SectionList() {
const { texts } = useSectionTexts()
const parts = [texts.guide.eligibility, texts.guide.documents, texts.guide.cost]
// The default theme draws no marker on a section, and Safari can then drop the list role.
// role="list" on the <ul> keeps it announced as a list.
return (
<ul role="list">
{parts.map((part) => (
<Section as="li" key={part.heading}>
<Heading as="h4">{part.heading}</Heading>
<p>{part.text}</p>
</Section>
))}
</ul>
)
}Props in this example:
ason Section
Warning: Don't forget
Put role="list" on the <ul>. Safari can stop announcing a list when its markers are hidden (1.3.1 Info and Relationships, A). Check it with VoiceOver in Safari.
A notice in Swedish on an English page
Text in a different language from the page needs its own language setting, so a screen reader uses the right voice. Wrap it in a nested KvirnProvider and spread useLocale().localeProps on the section. The section is also a named region, so a screen reader user can jump to it. In English, the notice says: “Snow clearing. We plough streets and cycle paths when more than five centimetres of snow has fallen.”
Snöröjning
Vi plogar gator och cykelvägar när det har fallit mer än fem centimeter snö.
import { Heading, KvirnProvider, Section, useLocale } from '@kvirn-ui/react'
import { useId } from 'react'
import { swedishNotice } from './texts.ts'
function SwedishNotice() {
// The nested provider below is what sets this language. localeProps is its lang and dir, so a
// screen reader switches voice for this region only.
const { localeProps } = useLocale()
const headingId = useId()
return (
<Section as="section" aria-labelledby={headingId} {...localeProps}>
<Heading as="h4" id={headingId}>
{swedishNotice.heading}
</Heading>
<p>{swedishNotice.text}</p>
</Section>
)
}
export function OtherLanguageSection() {
return (
<KvirnProvider locale="sv-FI">
<SwedishNotice />
</KvirnProvider>
)
}Props in this example:
ason Section
Warning: Don't forget
Mark each region in another language (3.1.2 Language of Parts, AA). Without it, a screen reader reads the text with the page’s language.
Accessibility#
What it does for you#
- APG pattern: none. A section is not a widget, so there is no APG pattern.
- Deviations: none
- Native elements used:
<div>by default. The consumer picks another withas(allowed elements below), and the element's own semantics apply.
Section is a plain container for a region of the page, such as a sidebar or a band of content. It adds no role, no ARIA, no text, no tabindex and no behaviour. Everything a user perceives inside a section comes from the consumer's children, which keep their own semantics and focus order. A section is not the Section part of Disclosure or Tabs: those are parts of another component.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Section | <div> → generic | none. The consumer adds it with the element | as="aside", "section" or "nav" with aria-labelledby give it a landmark role, and "li" a list item. Section.Root is a deprecated alias of the same component. Also exported as SectionRoot |
| Section | as | the chosen element's own | One element, chosen with a string. A value outside the list is a type error and, in JS, warns once in development and renders the <div>. className joins, style and refs pass |
| Section | attributes | passed through | aria-*, id, data-* and every other attribute reach the element unchanged. The part's class is its own: a className prop joins it, never replaces it |
| Section | never | no role, aria-*, tabindex, inert, aria-hidden | No click handler, no heading, no live region, no text |
useSection() gives the same rootProps (only className) for your own element.
It announces nothing.
What you need to do#
- Headings. Put a heading at the top of the section, at the level the page outline needs:
h2for a sidebar or a band under the page'sh1. Section can't know it (2.4.6 Headings and Labels, AA; 1.3.1 Info and Relationships, A). - Landmarks are opt-in, and named. The default
<div>is not a landmark.as="aside"witharia-labelledby={headingId}is complementary content,as="section"with it is a region worth jumping to, andas="nav"with it is a sidebar of navigation. A<section>without a name isgeneric(HTML-AAM), so it is useless as a landmark. Keep landmarks few: never make every band a landmark. A top-level<header>or<footer>becomesbannerorcontentinfo, so only one of each. - Reading and focus order. The children's DOM order. A sidebar that sits on the inline end at
64remcomes after the main content in the DOM. Never reorder withorderor grid placement against the DOM (1.3.2 Meaningful Sequence, A; 2.4.3 Focus Order, A). - Lists. A list of sections is a
<ul>with each section rendered as<li>(as="li"). The default theme draws no marker, and Safari can then expose the<ul>as a plain group:role="list"on the<ul>keeps it a list there. This is the same Safari problem as for a list of cards (see the Card component's Known issues). Check it with VoiceOver in Safari in your own service. - Nesting. A Card on a Section, yes. A Section inside a Card, no (a region inside a thing). A Section inside a Section only to switch between
surfaceandcanvas. - Scrolling. Never
overflowon the Section. A sidebar that scrolls on its own goes in a named scroll region that is a Tab stop (a ScrollArea does both). A sticky sidebar needsscroll-padding(2.4.11 Focus Not Obscured (Minimum), AA). - Not empty. Don't render a Section with no content: it still has padding and a surface.
- Language. Text in another language goes in a nested
KvirnProvider, withuseLocale().localePropson your own element (3.1.2 Language of Parts, AA).
Warning: Don't forget
Write the children in the order people should read and Tab through them, so a sidebar beside the main content comes after it in the code. Reordering with your own CSS breaks the match between what people see and what a keyboard or screen reader follows (1.3.2 Meaningful Sequence, 2.4.3 Focus Order).
Visual and modes#
Headless: Section ships no CSS. With the default theme (@kvirn-ui/theme/theme.css):
- Focus indicator: none of its own (a section is never focused). Children keep their own rings, never clipped.
- Target size: not applicable. Section has no controls of its own (2.5.8 Target Size (Minimum), AA).
- Contrast: text, links, muted text, control edges and focus rings are held to their minimums on the
surfaceandcanvaslooks by the theme's contrast check (1.4.3 Contrast (Minimum), AA; 1.4.11 Non-text Contrast, AA). The section's own boundary is decorative (too faint to count as contrast, 1.4.11 does not apply): the region is identified by its position, its heading and, where it is worth it, its landmark. - forced-colors behaviour:
surfaceandcanvasboth use the system's page background colour, and the section's thin border uses the system's text colour on all four sides. - reduced-motion behaviour: no motion. No hover, transition or pointer style.
- Reflow and text spacing: no fixed sizes, no
overflow,overflow-wrap: break-word, and the section can shrink in a grid. Media directly in the section never get wider than it. The reflow sweep runs every story at 320 CSS px and fails on horizontal overflow, with Finnish text and with a wide image (1.4.10 Reflow, AA). The section sets no fixed height, so with the text-spacing overrides it grows and nothing is clipped (1.4.12 Text Spacing, AA). - The no-padding option, with a focusable child flush to a viewport edge, would push the outer part of its focus ring off-screen: use it for frames whose children pad themselves, and for media.
Focus management#
- Initial focus: not moved. Section never moves focus.
- Trap: no.
- Restore to: not applicable.
- Never obscured by: Section renders no overlay. The default theme never sets
overflowon a section, so a child's focus ring is never clipped (2.4.11 Focus Not Obscured (Minimum), AA).
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 |
|---|---|---|
| Section | div (default), section, aside, nav, footer, header, article, li | The landmark or sectioning elements a region can be, and li for a list of sections. No main (Container), no form, no heading |
WCAG success criteria#
- 1.3.1 Info and Relationships (A): no role of its own, so the consumer's element and children decide the semantics (
section.test.tsx). - 1.3.2 Meaningful Sequence (A), 2.4.3 Focus Order (A): DOM order equals reading and focus order (the Tab rows above).
- 1.4.3 Contrast (Minimum) (AA), 1.4.11 Non-text Contrast (AA): the theme's contrast check covers the pairs on the
surfaceandcanvaslooks. 1.4.6 Contrast (Enhanced) is AAA and not counted toward AA. - 1.4.10 Reflow (AA): the reflow sweep at 320 CSS px, with Finnish text and with a wide image.
- 1.4.12 Text Spacing (AA): no fixed sizes or heights, so nothing is clipped (the text-spacing sweep applies the 1.4.12 spacing to every story and fails on a box that clips more content than it holds).
- 2.4.1 Bypass Blocks (A): a named landmark helps screen-reader users skip to it, where the consumer opts in.
- 2.4.11 Focus Not Obscured (Minimum) (AA): no clipping. 2.4.13 Focus Appearance is AAA and not counted toward AA.
- 4.1.2 Name, Role, Value (A): no role or name of its own to get wrong. A landmark's name is the consumer's.
Keyboard#
Section has no keys of its own. What you put in it keeps its own keys.
API reference#
import { Section, useSection } from '@kvirn-ui/react'Section
Renders <div> with no role. It takes every attribute of a <div> and passes ref to it, whichever element as picks. It is one element, so it is written <Section>; Section.Root still works but is deprecated and removed in 1.0. Also exported as SectionRoot. This is not the Section part of Disclosure or Tabs. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | – | Your own classes. They join kv-section and never replace it, so the theme keeps styling the section. |
as | 'div' | 'section' | 'aside' | 'nav' | 'footer' | 'header' | 'article' | 'li' | 'div' | Changes the element: aside, section or nav with aria-labelledby, header or footer, article, or li in a list of sections. Section adds no role. Another tag warns once in development. |
ref | Ref<HTMLElement> | – | Reaches the element, whichever it is. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-section | always | The part class. The default theme styles it. |
kv-section--surface | kv-section--canvas | class you add | The background: surface (the default) or canvas, which looks like the page again. |
kv-section--padding-none | -sm | -md | -lg | class you add | The padding. md is the default. none is for a frame whose children pad themselves, and for media. |
useSection
Takes no options. Spread rootProps on your own element, such as a <nav> with aria-labelledby. To add a class, join it with mergeProps.
Result
| Prop | Type | Default | Description |
|---|---|---|---|
rootProps | { className: 'kv-section' } | – | Spread on your element. |
Known issues#
- No visible region edge in the high-contrast themes. The
surfacelook on thecanvaslook has almost no contrast in the high-contrast themes, the same as in the standard themes. A sidebar there has no visible edge unless you colour one with a border colour of your own. This is decorative for WCAG, but a usability question. - Keyboard tests run in Chromium only. The keyboard rows run in Vitest browser mode on Chromium, not in WebKit. Test in Safari with your own assistive technology.
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 | section.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | section.test.tsx › adds no role, ARIA or tabindex; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | section.test.tsx › the section is skipped by Tab: focus goes through its children in DOM order |
| Focus order and management | pass | n/a | pass | section.test.tsx › the section is skipped by Tab: focus goes through its children in DOM order asserts focus (toHaveFocus); the component never takes or moves focus |
| 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 | n/a | n/a | n/a | native <div>, or the landmark element the consumer picks, with its own semantics; landmark semantics are the element's own native mapping; Section adds none; no state, focus or key handling |
| VoiceOver + Safari + iOS | n/a | n/a | n/a | native <div>, or the landmark element the consumer picks, with its own semantics; landmark semantics are the element's own native mapping; Section adds none; no state, focus or key handling |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | n/a | n/a | n/a | native <div>, or the landmark element the consumer picks, with its own semantics; landmark semantics are the element's own native mapping; Section adds none; no state, focus or key handling |
| TalkBack + Chrome + Android | n/a | n/a | n/a | native <div>, or the landmark element the consumer picks, with its own semantics; landmark semantics are the element's own native mapping; Section adds none; no state, focus or key handling |
| VoiceOver + Safari + macOS | n/a | n/a | n/a | native <div>, or the landmark element the consumer picks, with its own semantics; landmark semantics are the element's own native mapping; Section adds none; no state, focus or key handling |
What to check#
With a screen reader and the keyboard, try:
- With
as="aside"or"nav"and a name, the section appears in the landmarks list under that name. A plaindivsection does not appear. - A list of sections in VoiceOver on Safari is read as a list.