---
title: Keyboard focus and skip links
description: Accessibility helpers to handle focus management and Skip Link usage.
version: 11.18.1+HEAD.257af686b5
generatedAt: 2026-11-24T16:46:13.435Z
checksum: 090b7d977ba4be5e2c4c04d199a30a4048416c59f443a56985df2f80629d9c40
---

# Keyboard focus and skip links

<span id="focus-styling-tokens" />

## Keyboard focus styling

1. Use the blue `--token-color-stroke-action-focus` except for input fields and explicitly dark surfaces.
2. Use a 3px outline with a 2px transparent gap. Keep text, icon, and background colors unchanged.
3. Lists, tables, cards, and similar layouts replace the existing edge with a 3px focus-colored edge, with no gap. Use 2px if a scroll container's existing spacing would clip 3px. Hover styling takes precedence while focused.

Use `--token-color-stroke-action-focus-ondark` on local dark surfaces and `--token-color-stroke-action-focus-inverse` on surfaces using the opposite color scheme. See the [dark mode guide](/web/styling-and-themes/design-tokens/dark-mode/#choosing-the-right-variant).

Button, Anchor, Checkbox, Radio, and Switch select the on-dark token through `surface="dark"`, including inherited surface context. The outline keeps the same width and gap without changing text, icons, or backgrounds.

Page dark mode does not automatically select the dark surface style. Verify at least 3:1 contrast against the actual surrounding surface. The regular blue outline still falls below 3:1 on some dark-mode surfaces, including striped table rows and warning sections; their color treatment is pending design guidance.

| CSS custom property                         | Purpose               | Default           |
| ------------------------------------------- | --------------------- | ----------------- |
| `--token-color-stroke-action-focus`         | Default outline color | Theme blue        |
| `--token-color-stroke-action-focus-ondark`  | Local dark surface    | Theme light blue  |
| `--token-color-stroke-action-focus-inverse` | Opposite color scheme | Theme dependent   |
| `--focus-outline-width`                     | Outline width         | `0.1875rem` (3px) |
| `--focus-outline-offset`                    | Gap                   | `0.125rem` (2px)  |

Use the [focusOutline()](/web/ai-tools-and-resources/utilities/sass/#keyboard-focus) Sass helper or CSS:

```css
.my-action:focus-visible {
  outline: var(--focus-outline-width) solid
    var(--token-color-stroke-action-focus);
  outline-offset: var(--focus-outline-offset);
}
```

The gap shows the surface behind the element. Keep enough space around the outline so containers do not clip it.

Tab to these examples to compare the focus styles. The layout example also shows hover taking precedence:


```tsx
render(<div className={styles['dnb-focus-examples']}>
        <button type="button" className={styles['dnb-focus-examples__action']}>
          Action with gap
        </button>
        <button type="button" className={styles['dnb-focus-examples__layout']}>
          Layout without gap
        </button>
      </div>)
```


These components inherit the on-dark focus color from their Section. Tab through them to compare the outline with their normal appearance:


```tsx
render(<Section surface="dark" innerSpace breakout={false}>
        <Flex.Stack>
          <Flex.Horizontal gap="medium" align="center">
            <Button>Primary</Button>
            <Button variant="secondary">Secondary</Button>
            <Button variant="tertiary">Tertiary</Button>
            <Anchor href="#keyboard-focus-styling">Anchor</Anchor>
          </Flex.Horizontal>
          <Flex.Horizontal gap="medium" align="center">
            <Checkbox label="Checkbox" checked />
            <Radio label="Radio" name="focus-on-dark" />
            <Switch label="Switch" checked />
          </Flex.Horizontal>
        </Flex.Stack>
      </Section>)
```


This guidance applies to new and updated implementations. See [v13 focus compatibility guidance](/web/releases-and-upgrades/versions/eufemia/v13-info/#keyboard-focus-styling) when migrating custom styles.

## Focus Management

Focus is an important part of keyboard-only and screen reader navigation.

Make sure you set the focus properly on page or context changes. Consider using Reach Router because of its built-in accessibility features.

From a technical perspective, we need to assign an _invisible_ focus so the user can continue navigating inside this new content.

**Example setup:**

```html
<body>
  <nav><!-- focusable navigation --></nav>
  <main>
    <!-- more markup with focusable HTMLElements -->
    <h1 class="dnb-h--xx-large dnb-no-focus" tabindex="-1">Main Title</h1>
    <a href="/path">I'm now focusable on next tab</a>
  </main>
</body>
```

## Managing focus state

Make sure you:

- Set the focus on the content (e.g., `<h1 class="dnb-h--xx-large">`) after a navigation action initiated by the user.
- Set the focus into a _menu or navigation_ area if it has an opening mechanism.
- Set the focus back to the content once the menu or navigation area is closed.

More complex focus management is already built into the [Modal Component](/web/components/modal). The Modal disables focus on the content behind it, so the user can only navigate inside the modal.

## Helper tool

`@dnb/eufemia` has a built-in helper to manage basic focus handling.
This helper also handles both the `tabindex="-1"` and the `class="dnb-no-focus"` situations. What does it do?

1. You define beforehand what should get focus with a CSS selector (_class or id_). This (**setPageFocusElement**) can be set at the very first application start.
2. Later, once the focus should be set, you call a second function **_applyPageFocus_**. This function will use the previously defined selector and execute `domNode.focus()`.

### Focus helper

Set focus on an HTML element that exists inside the DOM. It can be any HTML element, regardless of whether it's an interactive element or not. Non-interactive elements will be handled by changing the `tabindex` to 0 alongside a CSS class `dnb-no-focus`, so no blue focus border is visible.

Simple example:

```js
import { applyPageFocus } from '@dnb/eufemia/shared/helpers'

applyPageFocus('.my-selector')
applyPageFocus('#my-id')
```

Asynchronous example:

```js
import {
  setPageFocusElement,
  applyPageFocus,
} from '@dnb/eufemia/shared/helpers'

// 1. Somewhere in your app, set either an element, or a CSS Selector
setPageFocusElement('.css-selector', 'MyCustomName')

// 2. Later you can call this action, once it's time to activate the new focus state
applyPageFocus('MyCustomName', (element) => {
  /* optional callback */
})
```

### Skip Link

`@dnb/eufemia` also has a small setup for a [skip link](https://www.w3.org/TR/WCAG20-TECHS/G1.html).

Our solution is CSS-only and should work for all kinds of application setups. Demo example below:


```tsx
render(<ChangeStylesOfSkipLink>
      <a className="dnb-skip-link--active" onClick={onClick} href="#dnb-app-content">
        Show Skip-Link
      </a>
    </ChangeStylesOfSkipLink>)
```


1. Place an anchor with an HTML class `.dnb-skip-link` as the very **first HTML element** tag:

```html
<a class="dnb-skip-link" href="#content-id">Skip to content</a>
```

2. Define a unique element **id**, such as `id="content-id"`, on your content wrapper:

```html
<body>
  <a class="dnb-skip-link" href="#content-id">Skip to content</a>
  <header>
    <nav>
      <!-- Nav links or content to skip -->
    </nav>
  </header>
  <main id="content-id">
    <!-- Content goes here -->
  </main>
</body>
```

That's it. The styles are included in both the **dnb-ui-basis** and **dnb-ui-core** styling packages.

**NB:** If you link the anchor to only a `<div id="content-id">`, then you have to make sure you also add a tabindex.

```html
...
<div id="content-id" tabindex="-1" class="dnb-no-focus">
  <!-- Content goes here -->
</div>
...
```
