Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

Section

A container for a region of the page, such as a sidebar or a band of content. It gives a region its own surface and padding. With the right element and a name, it can also be a landmark: a part of the page that screen readers list.

Package
@kvirn-ui/react
Testing
Automated. Core n/a, Release n/a

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.

Use cases#

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.

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.

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.

Props in this example:

  • as on 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.

Props in this example:

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.

Props in this example:

  • as on 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ö.

Props in this example:

  • as on 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 with as (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.

PartElement / roleARIANotes
Section<div> → genericnone. The consumer adds it with the elementas="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
Sectionasthe chosen element's ownOne 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
Sectionattributespassed througharia-*, 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
Sectionneverno role, aria-*, tabindex, inert, aria-hiddenNo 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: h2 for a sidebar or a band under the page's h1. 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" with aria-labelledby={headingId} is complementary content, as="section" with it is a region worth jumping to, and as="nav" with it is a sidebar of navigation. A <section> without a name is generic (HTML-AAM), so it is useless as a landmark. Keep landmarks few: never make every band a landmark. A top-level <header> or <footer> becomes banner or contentinfo, so only one of each.
  • Reading and focus order. The children's DOM order. A sidebar that sits on the inline end at 64rem comes after the main content in the DOM. Never reorder with order or 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 surface and canvas.
  • Scrolling. Never overflow on 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 needs scroll-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, with useLocale().localeProps on 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 surface and canvas looks 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: surface and canvas both 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 overflow on 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
Sectiondiv (default), section, aside, nav, footer, header, article, liThe 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 surface and canvas looks. 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.

PropTypeDefaultDescription
classNamestring–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.
refRef<HTMLElement>–Reaches the element, whichever it is.
Class or attributeValuesMeaning
kv-sectionalwaysThe part class. The default theme styles it.
kv-section--surface | kv-section--canvasclass you addThe background: surface (the default) or canvas, which looks like the page again.
kv-section--padding-none | -sm | -md | -lgclass you addThe 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

PropTypeDefaultDescription
rootProps{ className: 'kv-section' }–Spread on your element.

Known issues#

  • No visible region edge in the high-contrast themes. The surface look on the canvas look 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 + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apasssection.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apasssection.test.tsx › adds no role, ARIA or tabindex; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apasssection.test.tsx › the section is skipped by Tab: focus goes through its children in DOM order
Focus order and managementpassn/apasssection.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)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowsn/an/an/anative <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 + iOSn/an/an/anative <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 + Windowsn/an/an/anative <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 + Androidn/an/an/anative <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 + macOSn/an/an/anative <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 plain div section does not appear.
  • A list of sections in VoiceOver on Safari is read as a list.