Skip to main content
Login

Sign in to access your account

Content Switcher - National Design System

A row of joined buttons that switches between views of the same content, in one place on the page

Overview

A content switcher shows one view at a time, picked from a short row of joined buttons. It is a tab set with the class nds-content-switcher on its root: an nds-tab-list of nds-tab buttons, and an nds-tab-content area with one nds-tab-panel for each button. The open button has a solid fill.

Pick another component when:

  • the views are different sections of a page, or need long labels, icons, a vertical list or more buttons than fit in one row: Tabs
  • the choice is a form value that is sent with the form: Radio
  • the buttons run actions and do not change a view: Button

Markup

Preview

Every request you submitted, in all states.

<div class="nds-tabs nds-content-switcher"> <div class="nds-tab-list" role="tablist" aria-label="Request status"> <button type="button" class="nds-btn nds-secondary nds-tab" role="tab" aria-selected="true" aria-controls="panel-all" id="tab-all" tabindex="0"> <span class="nds-label">All</span> </button> <button type="button" class="nds-btn nds-secondary nds-tab" role="tab" aria-selected="false" aria-controls="panel-review" id="tab-review" tabindex="-1"> <span class="nds-label">In review</span> </button> <button type="button" class="nds-btn nds-secondary nds-tab" role="tab" aria-selected="false" aria-controls="panel-done" id="tab-done" tabindex="-1"> <span class="nds-label">Completed</span> </button> <button type="button" class="nds-btn nds-secondary nds-tab" role="tab" aria-selected="false" aria-controls="panel-archived" id="tab-archived" tabindex="-1"> <span class="nds-label">Archived</span> </button> </div> <div class="nds-tab-content"> <div class="nds-tab-panel" role="tabpanel" id="panel-all" aria-labelledby="tab-all" tabindex="0"> <p>Every request you submitted, in all states.</p> </div> <div class="nds-tab-panel" role="tabpanel" id="panel-review" aria-labelledby="tab-review" tabindex="-1" hidden> <p>Requests that the authority is reviewing. You do not need to do anything yet.</p> </div> <div class="nds-tab-panel" role="tabpanel" id="panel-done" aria-labelledby="tab-done" tabindex="-1" hidden> <p>Requests with a decision. Each record shows the decision and its date.</p> </div> <div class="nds-tab-panel" role="tabpanel" id="panel-archived" aria-labelledby="tab-archived" tabindex="-1" hidden> <p>Requests closed more than a year ago, kept for reference.</p> </div> </div> </div>

Built-in Features

  • Auto-initialization

    Every content switcher on the page starts by itself. Switching and the keyboard need no call.

  • Keyboard Navigation

    The arrow keys move between buttons, and left and right follow the reading direction. Home and End jump to the first and the last button. Enter or Space opens the focused button.

  • Three Sizes

    32, 40 and 48px buttons. The label size, the padding and the corners follow the size.

  • Loading Skeleton

    Gray bars stand in for the labels and the open panel until the script starts, so the row is never bare.

  • High Contrast and Reduced Motion

    The open button gets a border in high-contrast mode, and the transitions stop when the user prefers reduced motion.

  • Change Events

    Every switch fires nds:tabs:change with the new and the previous button and panel.

  • Programmatic Control

    Open a view, read the open panel or remove the behavior through NDS.Tabs or the element's ndsTabs property.

Best Practices

  • Use a content switcher for two to four short views of the same data, such as a date range, a status filter or a chart period.
  • Pick it over tabs when people must see the open view at a glance. A solid fill is easier to see than an underline on a busy page.
  • Keep labels to one or two words. The row does not scroll, so long labels push it past its container.
  • Keep the same buttons at all times. For choices that come and go, use a Filter.
  • Put the view people open most first. It opens when the page loads.
  • Give every button a panel. A switcher with no panels does not start. For a row of view buttons with no panels, use a button group and handle the clicks yourself.
  • Keep the buttons and the panels in the same order and the same number. Button one opens panel one, by their order in the markup.
  • Give nds-tab-list an aria-label, and pair each button and panel with aria-controls and aria-labelledby.

API

Data Attributes

Attribute Element Effect
aria-selected="true" .nds-tab Marks the button that opens when the page loads. With none, the first button opens
data-state="loading" .nds-content-switcher or .nds-tab-list The same as nds-loading, for a script that already sets states

CSS Custom Properties

Property Default Controls
--btn-group-radius var(--radius-md) Corner radius of the two ends of the row, the same at every size. Set it on .nds-tab-list
--btn-size 40px Button height, for a size between the three sizes. Set it on .nds-tab
--tab-button-gap var(--spacing-xs) Gap between a button’s icon and its label
--tab-button-padding-block 0 Padding above and below a button’s label
--tab-button-padding-inline the button padding Padding at the start and the end of a button. It follows the size
--tab-panel-padding 0 at the sides, var(--spacing-2xl) above and below Padding of a panel on both axes. A panel with nds-card keeps var(--spacing-2xl) at the sides
--tab-panel-padding-inline, --tab-panel-padding-block --tab-panel-padding Padding of a panel on one axis

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_content-switcher.scss.

TokenPreviewValue
--text-oncolor-primary
Read by --btn-color, color
var(--colors-base-white)
--divider-color
Read by border-inline-start-color

var(--colors-alpha-black-10)
Dark mode var(--colors-alpha-white-10)
--button-background-neutral-default
Read by --btn-bg, --btn-bg-hover, --btn-bg-active
var(--colors-neutral-950)
--button-background-primary-default
Read by --btn-bg, --btn-bg-hover, --btn-bg-active
var(--colors-primary-600)
--button-background-oncolor-disabled
Read by --btn-bg-disabled, --btn-indicator-active
var(--colors-alpha-white-20)
--button-background-transparent-hovered
Read by --btn-bg, --btn-bg-hover
var(--colors-alpha-white-20)
--button-background-transparent-pressed
Read by --btn-bg-active
var(--colors-alpha-white-40)
--button-background-transparent-selected
Read by --btn-bg-selected
var(--colors-alpha-white-30)

JavaScript

The Tabs controller, NDS.Tabs, runs the content switcher. The instance lives on the element as ndsTabs. It is there once the component starts: code that runs at page load waits for NDS.init.ready.

Method Effect
NDS.Tabs.init() Starts every switcher and tab set on the page that has not started yet
NDS.Tabs.create(element) Starts one switcher and returns its instance, or the instance it already has. Returns null when the switcher has no tab list, tabs or panels
NDS.Tabs.destroy(element) The same as instance.destroy()
instance.goTo(index) Opens a view by its position, from 0
instance.getActiveTabIndex() Returns the position of the open button
instance.getActiveTab(), instance.getActivePanel() Return the open button and its panel
instance.destroy() Removes the listeners. The markup stays as it is
Event Fired on Detail
nds:tabs:change .nds-content-switcher, and it bubbles tabIndex, tab, panel, previousTab, previousPanel
var switcher = document.querySelector('#request-status'); switcher.addEventListener('nds:tabs:change', function (e) { console.log('Opened view', e.detail.tabIndex); }); switcher.ndsTabs.goTo(2);

The full API is in the banner of _js/nds-tabs.js.

Last Modified Date: 20/11/2026 - 04:53 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks