When to use it#
- Use it between two blocks on different topics, where a line helps people see where one ends and the next begins.
- Keep a heading or some text on each side that says what the block is. The line does not say it, and it is not a heading. For a heading, use a Heading.
- If the line is only decoration, tell screen readers to skip it. See A line that is only decoration.
- Not for adding space between blocks. Use a layout such as a Stack.
Example#
Opening hours
Monday to Friday, 08:00 to 16:00.
Contact us
Call the citizen service on weekdays.
import { Divider, Heading } from '@kvirn-ui/react'
import { useDividerTexts } from './texts.ts'
export function DefaultDivider() {
const { texts } = useDividerTexts()
return (
<>
<Heading as="h4">{texts.hoursHeading}</Heading>
<p>{texts.hours}</p>
<Divider />
<Heading as="h4">{texts.contactHeading}</Heading>
<p>{texts.contact}</p>
</>
)
}Use cases#
A line that is only decoration
The footnote below is not a new topic, so the line is only decoration. Pass role="presentation" and a screen reader skips the line instead of announcing a separator.
Call the citizen service on weekdays.
Last updated 1 October.
import { Divider } from '@kvirn-ui/react'
import { useDividerTexts } from './texts.ts'
export function DecorativeLine() {
const { texts } = useDividerTexts()
return (
<>
<p>{texts.contact}</p>
<Divider role="presentation" />
<p>{texts.footnote}</p>
</>
)
}Warning: Don't forget
The line must not carry meaning alone. What the footnote is has to be clear from its text (1.3.1 Info and Relationships, Level A).
A stronger line between a decision and the next steps
The decision and the next steps are two topics, so the line stays a separator. Make it thicker and darker so it is easier to see. Set the CSS variables in your own stylesheet, on a class. The example sets them on the line so that it runs on its own.
Your decision
Your parking permit is approved.
What to do next
Pay the fee within 14 days to get the permit.
import { Divider, Heading } from '@kvirn-ui/react'
import type { CSSProperties } from 'react'
import { useDividerTexts } from './texts.ts'
// Set these in your own stylesheet, on a class. They are on the line here so the example runs on its own.
const strongerLine = {
'--kv-divider-width': '2px',
'--kv-divider-color': 'var(--kv-color-border-control)',
} as CSSProperties
export function StrongerLine() {
const { texts } = useDividerTexts()
return (
<>
<Heading as="h4">{texts.decisionHeading}</Heading>
<p>{texts.decision}</p>
<Divider style={strongerLine} />
<Heading as="h4">{texts.nextStepsHeading}</Heading>
<p>{texts.nextSteps}</p>
</>
)
}Warning: Don't forget
If you change the colour, keep the line clearly visible against the background when it matters to understanding (1.4.11 Non-text Contrast, Level AA).
Accessibility#
What it does for you#
- APG pattern: none. Divider is static content, not a widget.
- Deviations: none
- Native elements used:
<hr>. Noas: the element is the semantics.
Divider is the native <hr> element with a class, so the theme can draw and space it. It adds no ARIA attributes, no text and no behaviour. An <hr> has the built-in role separator (a break between two topics), and some screen readers announce it.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Divider | <hr> → built-in separator | none | class="kv-divider". Attributes and the ref reach the element unchanged |
| Divider | <hr role="presentation"> | passed through by the consumer | A purely visual line: not announced. The consumer chooses; the component never adds it |
| Divider | never | no tabindex, name | It needs no accessible name and is not interactive |
It announces nothing.
What you need to do#
- Pick the role on purpose. Keep the default
separatorwhen the blocks on each side are different topics. Passrole="presentation"when the line is only decoration, so screen readers skip it (1.3.1 Info and Relationships, A). - Don't carry meaning in the line alone. What the line separates must also be clear from headings or text (1.3.1 Info and Relationships, A; 1.4.1 Use of Color, A).
- Keep your own colour visible. If you change
--kv-divider-color, keep the line clearly visible against the background when it matters to understanding (1.4.11 Non-text Contrast, AA).
Visual and modes#
Divider ships no CSS of its own. With the default theme it is a thin, faint line with space above and below. The space, width, style and colour are CSS variables you can change. The line is a border, not a background, so it stays visible in forced colours mode (the user's own system colours). Target size and focus indicator do not apply, because the line cannot be focused. There is no motion.
Focus management#
- Initial focus: not moved. Divider never moves focus.
- Trap: no.
- Restore to: not applicable.
WCAG success criteria#
- 1.3.1 Info and Relationships (A): a break between topics is the native
<hr>and reads as a separator; a decorative one can berole="presentation"and reads nothing. - 1.4.11 Non-text Contrast (AA): the default line is decoration between blocks, and the content can be understood without it. If you make the line carry meaning, keep your own colour visible.
Keyboard#
Divider has no keys of its own. What you put in it keeps its own keys.
Announcements#
What a screen reader reads#
| State or action | Read aloud | Politeness | Test |
|---|---|---|---|
<Divider /> between two paragraphs | Above, separator, … (the virtual reader adds orientation and value text), Below | none | divider.test.tsx › a default divider reads as a separator between the paragraphs |
<Divider role="presentation" /> between them | Above, Below (no separator between the paragraphs) | none | divider.test.tsx › a presentation divider reads nothing between the paragraphs |
API reference#
import { Divider } from '@kvirn-ui/react'Divider
Renders <hr>, whose built-in role is separator. It takes every attribute of an <hr> and passes ref to it. It has no state, no hook and no as. With the default theme you change the line with the CSS variables below. Set them on the line, on a class or on any element above it. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
ref | Ref<HTMLHRElement> | – | Reaches the <hr> element. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-divider | always | The part class. The default theme draws the line and its margin with it. Your className joins it. |
--kv-divider-width | a length, such as 2px | How thick the line is. The default is the theme’s border width. |
--kv-divider-style | a border style, such as dashed | How the line is drawn. The default is solid. |
--kv-divider-color | a colour | The colour of the line. The default is the theme’s faint border colour. Keep your own colour visible against the background when the line matters to understanding. |
--kv-divider-margin-block | a length | The space above and below the line. |
--kv-divider-margin-inline | a length | The space at the start and end of the line. The default is none. |
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 | divider.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | divider.test.tsx: a default divider reads as a separator between the paragraphs, a presentation divider reads nothing between the paragraphs, has no axe violations as a separator and as presentation |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 2 rows, each names a test in divider.test.tsx |
| Focus order and management | n/a | n/a | n/a | an hr is not focusable |
| 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 <hr> with its own separator role (or role="presentation" set by the consumer), no state or key handling; nothing to operate |
| VoiceOver + Safari + iOS | n/a | n/a | n/a | native <hr> with its own separator role (or role="presentation" set by the consumer), no state or key handling; nothing to operate |
| Release (before 1.0 and each minor) | ||||
| JAWS + Chrome + Windows | n/a | n/a | n/a | native <hr> with its own separator role (or role="presentation" set by the consumer), no state or key handling; nothing to operate |
| TalkBack + Chrome + Android | n/a | n/a | n/a | native <hr> with its own separator role (or role="presentation" set by the consumer), no state or key handling; nothing to operate |
| VoiceOver + Safari + macOS | n/a | n/a | n/a | native <hr> with its own separator role (or role="presentation" set by the consumer), no state or key handling; nothing to operate |