When to use it#
- Use a link to go somewhere: another page, a place on this page or a file.
- Write text that says where the link goes: “Apply for a parking permit”, not “click here”.
- Use
kv-link--servicefor the link that starts an e-service (an online public service). - Not for an action that changes something, such as sending or saving: use a Button. A link has no disabled state: if the page isn’t available, show text instead.
Example#
You can apply for a parking permit online.
import { Link } from '@kvirn-ui/react'
import { useLinkTexts } from './texts.ts'
export function DefaultLink() {
const { texts } = useLinkTexts()
return (
<p>
{texts.sentenceBefore}
<Link.Root href="#apply">{texts.sentenceLink}</Link.Root>
{texts.sentenceAfter}
</p>
)
}Use cases#
A link that opens a new tab
Opening a new tab takes people somewhere they may not expect, so say so in the link’s name. Put Link.NewTabNotice inside the link: it adds that text in the language set on KvirnProvider. Link also adds noopener noreferrer to rel for you, so the new page can’t reach back to yours.
import { Link } from '@kvirn-ui/react'
import { useLinkTexts } from './texts.ts'
export function NewTab() {
const { texts } = useLinkTexts()
return (
<p>
<Link.Root href="https://www.digg.se/" target="_blank">
{texts.newTabLink} <Link.NewTabNotice />
</Link.Root>
</p>
)
}Props in this example:
targeton Link.Root
Information: Did you know?
Link does not check that you added the notice: there is no type error and no warning, so review every target="_blank" link by hand. No level A or AA criterion requires the warning (3.2.5 Change on Request is level AAA), but without it a screen reader user isn’t told that a new tab opens. Better still, don’t open new tabs.
The current page in a list of links
Mark the link to the page the user is on, so a screen reader can tell them where they are and the default theme shows it by weight as well as colour. Link doesn’t read your router: you decide which link is current.
import { Link } from '@kvirn-ui/react'
import { useState } from 'react'
import { useLinkTexts } from './texts.ts'
export function CurrentPage() {
const { texts } = useLinkTexts()
const [currentPage, setCurrentPage] = useState('overview')
const pages = [
{ id: 'overview', label: texts.navOverview },
{ id: 'apply', label: texts.navApply },
{ id: 'contact', label: texts.navContact },
]
return (
<nav aria-label={texts.navLabel}>
<ul>
{pages.map((page) => (
<li key={page.id}>
<Link.Root
href={`#${page.id}`}
current={currentPage === page.id ? 'page' : false}
onClick={() => setCurrentPage(page.id)}
>
{page.label}
</Link.Root>
</li>
))}
</ul>
</nav>
)
}Props in this example:
currenton Link.Root
Information: Did you know?
With a router (the part of your app that changes pages), compare the link’s address with the router’s own current address, and pass current="page" or false.
A link to a page in another language
Put the link in your own element with lang set to the language of its text, so a screen reader reads “Suomeksi” (in Finnish) in Finnish. hrefLang names the language of the page it goes to. It doesn’t change how the text is read.
This page is also available in Finnish: Suomeksi
import { Link } from '@kvirn-ui/react'
import { useLinkTexts } from './texts.ts'
export function OtherLanguage() {
const { texts } = useLinkTexts()
return (
<p>
{texts.otherLanguageIntro}
<span lang="fi">
<Link.Root href="#fi" hrefLang="fi">
{texts.otherLanguageLink}
</Link.Root>
</span>
</p>
)
}Warning: Don't forget
Link never sets lang for you. Without it, a screen reader reads the Finnish text with the page’s language (3.1.2 Language of Parts).
A link to a file
People decide before they tap, and some pay for their data by the megabyte. Put the file type and size in the link text itself, in brackets. Don’t leave them to a title, an icon alone or text beside the link. Offer a web page version where you can. as="a" makes this a plain <a>, so a router never handles the file.
The budget for next year is published as a file.
Prefer to read it on a page? Budget 2027 as a web page
import { Link, useFormat } from '@kvirn-ui/react'
import { useLinkFileTexts } from './texts.ts'
export function FileLink() {
const { texts } = useLinkFileTexts()
const format = useFormat()
const size = format.number(2.5, {
style: 'unit',
unit: 'megabyte',
maximumFractionDigits: 1,
})
return (
<>
<p>{texts.intro}</p>
<p>
<Link.Root as="a" href="#budget-2027-pdf">
{texts.title} ({texts.format}, {size})
</Link.Root>
</p>
<p>
{texts.htmlLine} <Link.Root href="#budget-2027">{texts.htmlLink}</Link.Root>
</p>
</>
)
}Props in this example:
ason Link.Root
Information: Did you know?
Write the size with useFormat, so the number and unit follow the page’s language: “2.5 MB” in English, “2,5 MB” in Swedish, “2,5 Mt” in Finnish. The example’s own text exists in all five languages.
The link that starts an e-service
The way in to the service should be easy to find among plain links. Add the class kv-link--service and put the icon first, in Link.Icon. The icon is hidden from screen readers, so the link’s name is only its text.
import { Icon, Link } from '@kvirn-ui/react'
import { useLinkTexts } from './texts.ts'
export function ServiceLink() {
const { texts } = useLinkTexts()
return (
<Link.Root href="#building-permit" className="kv-link--service">
<Link.Icon>
<Icon name="arrow-forward" size="24" />
</Link.Icon>
{texts.service}
</Link.Root>
)
}Accessibility#
What it does for you#
- APG pattern: none needed. A link is a native
<a href>(APG Link only covers non-native links, which Link never renders). - Deviations: none
- Native elements used:
<a href>, rendered by the app's registered router link component, or by a native<a>when none is registered oras="a"is given.<span>for the new-tab notice. Allowed elements:Link.Roottakesasas a component or a tag that renders an<a href>and forwards its ref;Link.NewTabNoticespan(default),emorsmall;Link.Iconspan(default) ori. Another tag on the last two warns once (as-not-allowed) and falls back tospan.
Link navigates. An action is a Button. Link has no disabled prop, by type: a disabled link isn't a thing, so remove the link or render plain text instead.
| Part | Element / role | ARIA | Notes |
|---|---|---|---|
| Link.Root | <a href> → link | aria-current from current | current: 'page', 'step', 'location', 'date', 'time' or true. false or absent sets nothing. data-current when set |
target="_blank" | none | rel="noopener noreferrer" is added to the consumer's own rel tokens, also with as="a" or an as component | |
| keyboard focus | none | data-focus-visible while the link matches :focus-visible | |
| another language | hrefLang passed through | <span lang="fi"><Link.Root href="/fi" hrefLang="fi">Suomeksi</Link.Root></span> (3.1.2) | |
| Link.Icon | <span>, decorative | aria-hidden="true" | class="kv-link-icon". Always hidden: aria-hidden can't be turned off, so the icon is never part of the link's name (2.5.3). Put it first. Also exported as LinkIcon |
| Link.NewTabNotice | <span>, part of the link's name | none | Text from link.newTabNotice. The consumer decides whether to hide it visually. Also exported as LinkNewTabNotice |
target="_blank" without a notice | – | Nothing: no type error and no dev warning. Adding the notice is the consumer's responsibility | |
link component doesn't render an <a> | – | Dev warning: the registered component must forward its ref and render an <a> |
The service link is className="kv-link--service" on a Link: a look and not a role, so the element, the role and the keys are the same as any link. It has no disabled state, because a link has none (an unavailable e-service is text, not a dimmed link).
useLink gives the same linkProps and the resolved newTabNotice text for your own <a> or router link.
It announces nothing.
What you need to do#
- Give every link text that says where it goes, in context (2.4.4 Link Purpose (In Context) (A)). No "click here".
- A link that opens a new window or tab should say so (AAA): put
<Link.NewTabNotice />inside everytarget="_blank"link, or better, don't open new tabs (3.2.5 Change on Request (AAA)). Link does not check this: there is no type error and no dev warning. WithuseLink, renderlink.newTabNoticeinside the link yourself. - If you hide the notice visually, hide it with a visually-hidden technique, not
display: noneoraria-hidden, so it stays in the name. Consider showing it: sighted users benefit too. - Set
current="page"on the link to the current page, for example in navigation. Link doesn't detect it from the router. - For a link in another language, put it in your own element with
lang(the text's language, 3.1.2 Language of Parts (AA)).hrefLangnames the target's language, not the text's. - Register a router link component that forwards its ref and renders an
<a>. Useas="a"for downloads and other links the router mustn't handle. - When overriding
newTabNotice, keep it true to what happens (3.2.5 Change on Request (AAA)) and consistent with any visible text (2.5.3 Label in Name (A)). - Style
[data-current]and[data-focus-visible](or:focus-visible). Don't show the current page by colour alone (1.4.1 Use of Color (A)).
Warning: Don't forget
A link that says only “click here” or “read more” fails 2.4.4 Link Purpose (In Context) unless the paragraph, list item or table cell around it says where it goes. Keep the new-tab notice in the link’s name. To hide it from sight, use a visually-hidden style (it hides text from sight but not from screen readers), not display: none or aria-hidden. If you change its words, keep them the same as any visible text (2.5.3 Label in Name).
Visual and modes#
- Focus indicator: headless. The browser's native ring by default. The default theme restyles it to at least 2px at 3:1 (2.4.7 Focus Visible (AA); 2.4.13 Focus Appearance (AAA)).
- Target size: inline links in a sentence are exempt from 2.5.8 Target Size (Minimum) (AA). The default theme sets a minimum size for standalone links, and the service link and a Navigation item are as tall as the theme's control height (taller in the comfortable density, shorter in the compact one). A story asserts the 24px threshold for the service link, and another for a navigation item in the compact density.
- forced-colors behaviour: a native
<a href>, so the system's link colour applies. The service link keeps a thin edge in that colour, and its icon block is not filled: it has a divider in that colour, so the boundary survives (1.4.11 Non-text Contrast (AA)). A link withcurrentis bolder in the default theme, so it is never shown by colour alone (1.4.1 Use of Color (A)). How the current page looks in a list of links, in forced colours too, is described in Navigation's contract (a fill and a bolder weight, and a straight bar in forced colours). A link in running text has 3:1 contrast against the body text (checked by the theme's contrast check) and is underlined on hover; the contrast themes, forced colours and a link in grey or red text (a caption,small, help text, an error message) keep the underline at rest (1.4.1). The forced-colours sweep checks that every link keeps a visible boundary and shows a focus indicator when it has focus (1.4.11). - reduced-motion behaviour: no motion, and the reduced-motion sweep checks that no animation keeps looping (2.3.3).
- Reflow and text spacing: the reflow sweep runs every story at 320 CSS px and fails on horizontal overflow (1.4.10 Reflow, AA). The text-spacing sweep applies the 1.4.12 spacing and fails when a box clips its text.
Warning: Don't forget
If you restyle links, keep a link in running text clear by more than colour (1.4.1 Use of Color), keep a visible focus ring (2.4.7 Focus Visible), and keep a link that stands alone at least 24 × 24 CSS pixels (2.5.8 Target Size (Minimum)).
Focus management#
- Initial focus: not moved. Link never moves focus.
- Trap: no.
- Restore to: not applicable. Where focus goes after a client-side navigation is the router's or the app's job (for example, to the new page's
h1). - Never obscured by: Link renders no overlay.
WCAG success criteria#
- 2.1.1 Keyboard (A): native
<a href>, Enter (Keyboard rows above). - 2.4.4 Link Purpose (In Context) (A): consumer text, plus the new-tab notice in the name.
- 2.4.7 Focus Visible (AA):
data-focus-visible. - 3.1.2 Language of Parts (AA): yours, a
langancestor on your own element.hrefLangis only passed through (link.test.tsx › passes hrefLang through). - 3.2.5 Change on Request (AAA, so it does not count toward the AA bar): the translated new-tab notice warns people before a link opens a new tab. Using it is the consumer's job: Link doesn't warn when it's missing.
- 4.1.2 Name, Role, Value (A): role
link,aria-current(link.test.tsx). - 1.4.1 Use of Color (A): the current page is shown by weight as well as colour, and a link in running text keeps its underline (Visual / modes above).
- 1.4.11 Non-text Contrast (AA): the service link's boundary survives in forced colours (Visual / modes above).
- 2.5.3 Label in Name (A):
Link.Iconis hidden from assistive technology, so the name is the visible text. - 2.5.8 Target Size (Minimum) (AA): a story asserts the service link at 24 × 24 CSS px. Other standalone links are not tested.
Keyboard#
- Focus
- native
- Selection follows focus
- n/a
- Arrows wrap
- n/a
- Shortcuts
- none
A native <a href>: one Tab stop, in DOM order, with no tabindex. Enter is native.
| Key | Where | What happens |
|---|---|---|
| Tab | Link | Moves focus to the link Test: link.test.tsx › keyboard › Tab moves focus to the link |
| Shift+Tab | Link | Moves focus to the previous focusable element, and off the link Test: link.test.tsx › keyboard › Shift+Tab moves focus off the link |
| Enter | Link | Follows the link Test: link.test.tsx › rendering › Enter activates the link; Space does not |
| Enter | Router link | Follows the link through the registered router, without a page load Test: link.test.tsx › router link › Enter follows a router link without a page load |
| Enter | Link with target=_blank | Opens the link in a new tab. With the notice added, the name already said it would (3.2.5, AAA) Test: link.test.tsx › keyboard › Enter on a new-tab link does not intercept the browser’s own handling |
| Space | Link | Not handled (native: scrolls the page). Doesn't follow the link. Focus stays Test: link.test.tsx › rendering › Enter activates the link; Space does not |
Escape, arrow keys and Home / End are not handled.
API reference#
import { Link, useLink } from '@kvirn-ui/react'Link.Root
Renders <a href> with the role link, rendered by the router link you registered on KvirnProvider (linkComponent), or a native <a> when none is. It takes every attribute of that element and passes ref to it. There is no disabled prop. Also exported as Link and LinkRoot. The default theme is described on Theming.
| Prop | Type | Default | Description |
|---|---|---|---|
current | 'page' | 'step' | 'location' | 'date' | 'time' | boolean | – | Marks the link as the current item in a set, as aria-current. Link does not detect it from the router. false or absent sets nothing. |
target | string | – | Passed to the element. "_blank" opens a new tab and adds rel="noopener noreferrer" to your own rel tokens. |
rel | string | – | Your own rel tokens, kept. A new-tab link gets noopener noreferrer added once. |
messages | Partial<KvirnMessages['link']> | – | Overrides link.newTabNotice for this link and its Link.NewTabNotice. |
as | ElementType | the registered router link, or <a> | Changes the element to a component of your own, with its props set on the Link. Link.Root as="a" bypasses the registered router link. It must render an <a href> and forward its ref. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-link | always | The part class. The default theme styles it. |
kv-link--service | class you add | The one link that starts an e-service: an outlined label with the icon in a block. A look, not a role. Theme variant. |
aria-current | "page", "step", "location", "date", "time" or "true" | From current. Not passed directly. |
data-current | present or absent | The link has current set. |
data-focus-visible | present or absent | The link has keyboard focus (:focus-visible). |
Link.NewTabNotice
Renders <span> with the text of link.newTabNotice, such as (opens in a new tab)
. It is part of the link’s name. Also exported as LinkNewTabNotice.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | Your own text. It wins over every message. Empty text falls through to the message. |
as | 'span' | 'em' | 'small' | 'span' | Changes the element. Another tag warns once in development. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-link-new-tab-notice | always | The part class. Your own class joins it. |
Link.Icon
Renders <span aria-hidden="true"> for a decorative icon, first in the link. Also exported as LinkIcon.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | The icon, for example <Icon name="arrow-forward" size="24" />, or any decorative SVG. |
as | 'span' | 'i' | 'span' | Changes the element. It stays decorative: aria-hidden and the class are kept. |
| Class or attribute | Values | Meaning |
|---|---|---|
kv-link-icon | always | The part class. Your own class joins it. |
aria-hidden | "true" | Always set, and it cannot be turned off, so the icon is never part of the name. |
useLink
Options
| Prop | Type | Default | Description |
|---|---|---|---|
current | 'page' | 'step' | 'location' | 'date' | 'time' | boolean | – | Sets aria-current and data-current. false or absent sets nothing. |
target | string | – | Mirrors HTML target. "_blank" adds rel="noopener noreferrer". |
rel | string | – | Your own rel tokens, kept. |
messages | Partial<KvirnMessages['link']> | – | Per-instance message overrides. |
Result
| Prop | Type | Default | Description |
|---|---|---|---|
linkProps | LinkPartProps | – | Spread on an <a href> or your router link: class, target, rel, aria-current, focus handlers. |
isCurrent | boolean | – | Whether current is set. |
isFocusVisible | boolean | – | Whether the link has keyboard (:focus-visible) focus. |
opensInNewTab | boolean | – | True for target="_blank": render newTabNotice inside the link. |
newTabNotice | string | – | The resolved link.newTabNotice text, for example (opens in a new tab). |
Strings
These are the default texts in @kvirn-ui/i18n.
For your whole app, pass messages to KvirnProvider. For one Link, pass its messages prop.
link.newTabNotice
Tells users a link opens in a new tab. It is part of the link’s name, used by Link.NewTabNotice and useLink().newTabNotice.
| Language | Default text |
|---|---|
| Svenska | (öppnas i en ny flik) |
| Suomi | (avautuu uuteen välilehteen) |
| Norsk bokmål | (åpnes i en ny fane) |
| Norsk nynorsk | (blir opna i ei ny fane) |
| English | (opens in a new tab) |
Known issues#
- 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.
- A
target="_blank"link with no notice is not flagged. Neither a type error nor a dev warning catches it, so review it by hand.
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 | link.stories.tsx, every story, 4 themes |
| Markup and ARIA (roles, names, ids, states) | pass | n/a | pass | link.test.tsx › current="page" sets aria-current and data-current; expectNoA11yViolations |
| Keyboard contract rows (Vitest browser) | pass | n/a | pass | 6 rows, each names a test (link.test.tsx › keyboard › Tab moves focus to the link) |
| Focus order and management | pass | n/a | pass | link.test.tsx asserts focus (toHaveFocus); first rule: keyboard › Tab moves focus to the link |
| 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 a screen reader and the keyboard, try:
- Tab to the link: the focus ring shows, and "link" and the link text are read.
- Press Enter: the link is followed. Space does not follow it.
- The link to the current page is read as current.
- A link that opens a new tab reads "(opens in a new tab)" as part of its name.
- A link in another language is read in that language's voice.