Overview
A tag is a small <span> with the nds-tag class and a label, with an optional icon. A standard tag shows a category or metadata, such as a topic, a type or a region. A status tag carries data-status and shows the state of an item, such as a request or an order, with a dot before the label. Tags sit together in an nds-tags group.
Pick another component when:
Markup
Variants
A row on .nds-tag:not([data-status]) applies to a standard tag only, and a row on .nds-tag[data-status] to a status tag only. In the Group structure, a row on .nds-tag changes every tag. (start) puts the icon before the label. Icon only has two rows: make both changes.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Standard (default) | — | — | One tag for a category or metadata |
| Structure | Status | canon #tag-status |
— | One tag for the state of an item, with a dot before the label |
| Structure | Group | canon #tag-group |
— | Several tags in a row that wraps, with an even gap |
| Color | Neutral (default) | — | — | For general labels |
| Color | Green | .nds-green |
.nds-tag:not([data-status]) |
Pick the color by meaning |
| Color | Blue | .nds-blue |
.nds-tag:not([data-status]) |
Pick the color by meaning |
| Color | Yellow | .nds-yellow |
.nds-tag:not([data-status]) |
Pick the color by meaning |
| Color | Red | .nds-red |
.nds-tag:not([data-status]) |
Pick the color by meaning |
| Color | On color (hint: For a deep primary or dark background) | .nds-oncolor |
.nds-tag:not([data-status]) |
The DGA white look for a standard tag on a deep primary or dark background. It replaces the color classes. A status tag keeps its colors: give the dark surface data-theme="dark" instead. Inside an on-color area (data-theme="dark oncolor"), the tag already takes this look: skip the class |
| Status | Neutral (default) | — | — | A state with no meaning of its own, such as submitted or draft |
| Status | Success | [data-status="success"] |
.nds-tag[data-status] |
A good result, such as approved or complete |
| Status | Info | [data-status="info"] |
.nds-tag[data-status] |
A state to note, such as in review |
| Status | Warning | [data-status="warning"] |
.nds-tag[data-status] |
A state that needs action soon, such as expiring |
| Status | Error | [data-status="error"] |
.nds-tag[data-status] |
A failed or blocked state, such as rejected |
| Status | Critical (hint: The same look as Error) | [data-status="critical"] |
.nds-tag[data-status] |
The same look as Error. Keep it for system-level alerts |
| Style | Light (default) | — | — | A light fill in the tag’s color |
| Style | Outline | .nds-outline |
.nds-tag:not([data-status]) |
No fill and a darker border, for a quieter standard tag |
| Style | Dark (hint: A solid fill with light text) | .nds-dark |
.nds-tag[data-status] |
A solid fill in the status color and light text, for a status that must stand out |
| Style | Ghost (hint: No fill and no border) | .nds-ghost |
.nds-tag[data-status] |
No fill, no border and neutral text beside the colored dot, for a quiet status |
| Size | MD (default) | — | — | 32px high. It needs no class |
| Size | SM | .nds-sm |
.nds-tag |
24px high, for cards and table rows |
| Size | XS | .nds-xs |
.nds-tag |
20px high, for dense lists |
| Content | Label (default) | — | — | Text only |
| Content | Icon and label | canon #tag-icon |
.nds-tag:not([data-status]) (start) |
An icon before the label. A font icon, <i class="hgi hgi-stroke hgi-NAME">, works too |
| Content | Icon only | canon #tag-icon |
.nds-tag:not([data-status]) (start) |
A square tag that shows only its icon, for tight spaces |
| Content | Icon only | .nds-icon-only |
.nds-tag:not([data-status]) |
The same: hides the label from view. Screen readers still read it, so keep the label |
| Rounded | Rounded | .nds-rounded |
.nds-tag:not([data-status]) |
Fully round ends. A status tag is always round |
| Center | Center (hint: Group only) | .nds-center |
.nds-tags |
Centers the tags in their row |
Built-in Features
-
Pure CSS
Tags need no JavaScript. Every color, style and size comes from classes and attributes.
-
Label Truncation
A long label stays on one line and ends with an ellipsis at 160px. A tag never grows wider than its container: it shrinks first, and the label is cut sooner.
-
Color by Class or Status
A class such as
nds-greencolors a standard tag.data-statuscolors a status tag, which ignores the color classes. -
Accessible Icon Only
An icon-only tag hides its label from view but not from screen readers, so the tag keeps its name.
Best Practices
- Use tags for labels that people read and do not click. For a label the user picks or removes, use Chips.
- Use a status tag for the state of an item. Write the state in the label: every status shows the same dot, so the color alone does not name it.
- Show a state with a status tag, also when the brief asks for an icon or a shape for each state. Its label names the state, so color is not the only cue.
- Do not put an icon in a status tag: it shows beside the dot, so the tag has two markers. A standard tag with a color class and an icon shows a category, never a state.
- Pick the color by meaning, and give tags of the same kind the same color.
- Pick the style by weight. A standard tag is light, or outline to stay quiet. A status tag is light, dark to stand out, or ghost to stay quiet.
- Keep labels to one to three words. A label longer than 160px ends with an ellipsis.
- Put related tags in one
nds-tagsgroup, so they share the gap and wrap together. - In a List, leave the size class off. The list makes a tag SM, a small list (
nds-sm) XS, and a large list (nds-lg) MD. To keep one tag at 32px there, give itnds-md. - Keep the label of an icon-only tag, and give its icon
aria-hidden="true". Screen readers read the label. - On a deep primary surface, give the surface
data-theme="dark oncolor primary": a standard tag takes the DGA white look, and a status tag its dark-mode colors. See Color Areas. On a neutral or other dark surface, give itdata-theme="dark": every tag takes its dark-mode colors. For one standard tag, addnds-oncolor.
API
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-status |
.nds-tag |
neutral, success, info, warning, error or critical makes a status tag: a dot before the label and fully round ends. It ignores the color classes. critical gives the Error look: keep it for system-level alerts |
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-neutral |
.nds-tag |
The same as no color class |
nds-gray |
.nds-tag |
The same as no color class |
CSS Custom Properties
Set these on the tag, or on a parent to reach every tag inside it. They win over the size classes, the color classes, the statuses and the styles.
| Property | Default | Controls |
|---|---|---|
--tag-bg |
var(--tag-background-neutral-light) |
Background |
--tag-text |
var(--tag-text-neutral) |
Label color |
--tag-border |
var(--tag-border-neutral-light) |
Border color |
--tag-icon |
var(--tag-icon-neutral) |
Icon and status dot color |
--tag-height |
32px |
Height. An icon-only tag uses it as its width too |
--tag-fs |
var(--typo-text-md-FS) |
Font size |
--tag-padding-inline |
var(--spacing-lg) |
Padding at the start and the end |
--tag-dot-size |
10px |
Size of the status dot |
--tag-label-max |
160px |
Widest the label gets before it ends with an ellipsis |
Tokens
Set a token at :root, or on a wrapper to reach every tag inside it. Give a token with a Dark mode value a dark override too: see Tokens.
Source: the tag group in _sass/tokens/_components.scss.
| Token | Preview | Value |
|---|---|---|
--tag-background-neutral | var(--colors-neutral-600) | |
--tag-background-neutral-light | var(--colors-neutral-50)Dark mode var(--colors-alpha-white-10) | |
--tag-background-oncolor | var(--colors-alpha-white-20) | |
--tag-text-neutral | var(--colors-neutral-800)Dark mode var(--colors-neutral-100) | |
--tag-text-success | var(--colors-green-800)Dark mode var(--colors-green-400) | |
--tag-text-info | var(--colors-blue-800)Dark mode var(--colors-blue-400) | |
--tag-text-warning | var(--colors-yellow-800)Dark mode var(--colors-yellow-400) | |
--tag-text-error | var(--colors-red-800)Dark mode var(--colors-red-400) | |
--tag-icon-neutral | var(--colors-neutral-800)Dark mode var(--colors-neutral-300) | |
--tag-icon-success | var(--colors-green-800)Dark mode var(--colors-green-400) | |
--tag-icon-info | var(--colors-blue-800)Dark mode var(--colors-blue-400) | |
--tag-icon-warning | var(--colors-yellow-800)Dark mode var(--colors-yellow-400) | |
--tag-icon-error | var(--colors-red-800)Dark mode var(--colors-red-400) | |
--tag-background-success | var(--colors-green-700) | |
--tag-background-success-light | var(--background-success-light)Dark mode var(--colors-green-alpha-10) | |
--tag-background-info | var(--colors-blue-600) | |
--tag-background-info-light | var(--background-info-light)Dark mode var(--colors-blue-alpha-10) | |
--tag-background-warning | var(--colors-yellow-700) | |
--tag-background-warning-light | var(--background-warning-light)Dark mode var(--colors-yellow-alpha-10) | |
--tag-background-error | var(--colors-red-600) | |
--tag-background-error-light | var(--background-error-light)Dark mode var(--colors-red-alpha-10) | |
--tag-border-neutral | var(--colors-neutral-600)Dark mode var(--colors-neutral-300) | |
--tag-border-neutral-light | var(--colors-neutral-200)Dark mode var(--colors-neutral-400) | |
--tag-border-oncolor | var(--colors-alpha-white-60) | |
--tag-border-success | var(--colors-green-700)Dark mode var(--colors-green-400) | |
--tag-border-success-light | var(--border-success-light)Dark mode var(--colors-green-400) | |
--tag-border-info | var(--colors-blue-700)Dark mode var(--colors-blue-400) | |
--tag-border-info-light | var(--border-info-light)Dark mode var(--colors-blue-400) | |
--tag-border-warning | var(--colors-yellow-700)Dark mode var(--colors-yellow-400) | |
--tag-border-warning-light | var(--border-warning-light)Dark mode var(--colors-yellow-400) | |
--tag-border-error | var(--colors-red-700)Dark mode var(--colors-red-400) | |
--tag-border-error-light | var(--border-error-light)Dark mode var(--colors-red-400) | |
--tag-dot | var(--colors-alpha-white-60) |
It also reads these shared tokens. A change to one also changes other components.
Source: the var() reads in _sass/components/_tag.scss.
| Token | Preview | Value |
|---|---|---|
--text-oncolor-primary | var(--colors-base-white) |