Skip to main content
Login

Sign in to access your account

Chips - National Design System

A chip is a small button for a choice, a filter or a value the user can remove

Overview

A chip is a small <button> with the nds-chip class, a color class and a label, with an optional icon. Chips sit together in an nds-chips group, as filter choices, categories or picked values. A chip needs no script for its look; your script sets it selected when the user picks it.

Pick another component when:

  • the label only describes something and cannot be clicked: Tags
  • the chips are the values of a field the user types into: Tag Input
  • the choices filter a list of items: Filter, which draws its own chips

Markup

Options
Structure
Color
Size
Content
More
Preview
<button type="button" class="nds-chip nds-primary"> <span class="nds-label">Services</span> </button>

Built-in Features

  • Pure CSS

    No JavaScript needed for the look. Every color, size and state comes from classes and attributes.

  • Interactive States

    Hover, pressed, selected, disabled, and a focus ring for keyboard users. On color chips keep a visible ring on a dark background.

  • Label Truncation

    A label longer than 160px ends with an ellipsis. A label that holds a formatted number, such as a price range, is never cut. --truncate sets how many lines it shows first.

  • Composable

    Combines with icons, the rounded shape, the on color version and chip groups. Tag Input, Multiselect and Filter build their removable chips with NDS.buildChip().

Best Practices

  • Use chips for choices the user clicks: filters, categories and picked values. For a label that only describes something, use a Tag.
  • Use one color for every chip of a choice. The selected state shows which one is on, so do not use a second color for it.
  • When a chip turns on and off, set data-state="selected" and aria-pressed="true" together, and aria-pressed="false" when it is off.
  • Put related chips in one nds-chips group, so they share the gap and wrap together.
  • Keep labels to one or two words. A label longer than 160px is cut with an ellipsis.
  • Add an icon only when it helps the user recognize the choice.
  • Give each chip type="button", so a chip inside a form does not send the form.
  • On a deep primary surface, give the surface data-theme="dark oncolor primary": every chip inside takes the DGA white look. See Color Areas. For one chip, add nds-oncolor instead. On a neutral or other dark surface, give it data-theme="dark" for the dark-mode chips.

API

Other Classes

Class Element Effect
nds-green .nds-chip The same as nds-primary
nds-gray .nds-chip The same as nds-neutral
nds-md .nds-chip The same as no size class: 24px

Data Attributes

Attribute Element Effect
data-state~="selected" .nds-chip The selected look
data-state~="disabled" .nds-chip The disabled look, the same as the disabled attribute
data-state~="hover", data-state~="pressed", data-state~="focused" .nds-chip Shows that look without a pointer or a keyboard, for a design review

CSS Custom Properties

Set these on the chip. --chip-size also reaches it from a parent, and it wins over the size classes. The color classes set --chip-bg and --chip-text.

Property Default Controls
--chip-size 24px Height
--chip-bg var(--chip-background-neutral-default) Background
--chip-text var(--chip-text-neutral-default) Label color
--chip-icon --chip-text Icon color
--truncate 1 Lines the label shows before the ellipsis

Tokens

Set a token at :root, or on a wrapper to reach every chip inside it. Give a token with a Dark mode value a dark override too: see Tokens.

Source: the chips group in _sass/tokens/_components.scss.

TokenPreviewValue
--chip-background-neutral-default
var(--background-neutral-light)
Dark mode var(--colors-alpha-white-10)
--chip-background-neutral-hovered
var(--colors-neutral-200)
Dark mode var(--colors-alpha-white-20)
--chip-background-neutral-pressed
var(--colors-neutral-300)
Dark mode var(--colors-alpha-white-30)
--chip-background-neutral-selected
var(--colors-neutral-700)
Dark mode var(--colors-neutral-300)
--chip-background-neutral-focused
var(--background-neutral-light)
Dark mode var(--colors-alpha-white-10)
--chip-background-oncolor-defaultvar(--colors-base-white)
--chip-background-oncolor-hoveredvar(--colors-alpha-white-80)
--chip-background-oncolor-pressedvar(--colors-alpha-white-60)
--chip-background-oncolor-selectedvar(--colors-alpha-white-70)
--chip-background-oncolor-focusedvar(--colors-base-white)
--chip-background-oncolor-disabledvar(--colors-alpha-white-20)
--chip-background-primary-default
var(--colors-primary-100)
Dark mode var(--colors-primary-alpha-10)
--chip-background-primary-hovered
var(--colors-primary-200)
Dark mode var(--colors-primary-alpha-20)
--chip-background-primary-pressed
var(--colors-primary-400)
Dark mode var(--colors-primary-alpha-30)
--chip-background-primary-selectedvar(--colors-primary-600)
--chip-background-primary-focused
var(--colors-primary-100)
Dark mode var(--colors-primary-alpha-10)
--chip-text-neutral-default
var(--colors-base-black)
Dark mode var(--colors-base-white)
--chip-text-neutral-selected
var(--colors-base-white)
Dark mode var(--colors-base-black)
--chip-text-primary-default
var(--colors-primary-800)
Dark mode var(--colors-primary-200)
--chip-text-primary-pressed
var(--colors-primary-900)
Dark mode var(--colors-primary-100)
--chip-text-primary-selectedvar(--colors-base-white)
--chip-text-primary-focused
var(--colors-primary-800)
Dark mode var(--colors-primary-200)
--chip-text-oncolor-defaultvar(--colors-base-black)
--chip-text-disabledvar(--colors-neutral-400)
--chip-text-oncolor-disabledvar(--colors-alpha-white-40)

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

Source: the var() reads in _sass/components/_chips.scss.

TokenPreviewValue
--background-disabled
Read by background-color

var(--colors-neutral-200)
Dark mode var(--colors-neutral-700)

JavaScript

A chip has no script of its own. NDS.buildChip() builds a removable chip for your own list of values.

Method Effect
NDS.buildChip(label, options) Returns a removable chip: a <button> with the label and a cancel icon. options.chipClass adds classes, options.data adds data attributes, options.onRemove runs on a click anywhere on the chip, options.disabled disables it, and options.signal is an AbortSignal: after it aborts, a click no longer calls onRemove
NDS.keepChipFocus(chips, render, fallback) Runs render, which removes a chip. If a chip had focus, it then focuses the chip in the same place, or fallback when none is left. chips is a function that returns the live chips. Call it from the remove handler of a chip built with NDS.buildChip()
var chips = document.querySelector('#picked'); chips.appendChild(NDS.buildChip('Riyadh', { chipClass: 'nds-neutral nds-rounded', data: { value: 'riyadh' }, onRemove: function (e) { e.currentTarget.remove(); } }));

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

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