# Badges

A **badge** is a small, non-interactive indicator attached to another element. It can show a status, category, or count for the item it accompanies.

## Usage

Badges can display short text, numbers, or an icon. Place them close to the item they describe so the meaning stays clear.

![Badge](<../images/badge.png>)

### When to use

- To label the state or category of an item.
- To count new, unread, or pending items on an icon, tab, or navigation entry.
- To signal that something changed since the user last looked.

### Best practices

- Keep badge text short and specific.
- Use whole numbers for counts.

## Design

### Badge label

A label badge shows the state or category of a single object, such as `Active` or `Draft`. It is available in neutral or status colors (success, danger, etc).

Every status color comes in two styles.

- Use the **subtle** style by default.
- Use the **emphasis** style when the badge needs to stand out.

![Label badge](<../images/badge-label.png>)

### Badge count

A badge count shows how many items need the user's attention, such as unread messages or pending requests. Use it when the exact quantity of new items matters. Keep counters to three characters or fewer, such as `99+`.

![Count badge](<../images/badge-count.png>)

### Badge dot

A badge dot signals change without showing a count. It tells the user that something changed since they last looked.

![Dot badge](<../images/badge-dot.png>)

## Code

### Usage

```
import { SiBadgeComponent } from '@siemens/element-ng/badge';

@Component({
  template: `<si-badge type="success" icon="element-validation-success">Success</si-badge>`,
  imports: [SiBadgeComponent, ...]
})
```

### Background colors

To set a badge's background color, choose between the following status tokens:

| Status | Bolder status |
| --- | --- |
| `default` |  |
| `inverse` |  |
| `primary` |  |
| `secondary` |  |
| `info` | `info-emphasis` |
| `success` | `success-emphasis` |
| `caution` | `caution-emphasis` |
| `warning` | `warning-emphasis` |
| `danger` | `danger-emphasis` |
| `critical` | `critical-emphasis` |

For a more prominent appearance use tokens with the `-emphasis` postfix.

```
<!-- Angular component -->
<si-badge type="critical-emphasis">Critical</si-badge>
```

### Native HTML markup

There are also various badge CSS classes you can use on native HTML elements: `badge`, `badge-dot`, and `badge-text`.

To set a badge's background color, apply the `.bg-{status token}` utility classes:

```
<div role="status" class="badge bg-critical-emphasis">Critical</div>
```

The `badge-dot` class provides a smaller dot that can be placed at the side of an icon:

```
<i role="status" aria-label="notifications" class="icon element-alarm-filled badge-dot"></i>
```

The `badge-text` class provides the ability to apply a short text at the side of an icon:

```
<div role="status" aria-label="More than 99 notifications">
  <i class="icon element-alarm-filled"></i>
  <span class="badge-text" aria-hidden="true">99+</span>
</div>
```

### Accessibility considerations

Badges can confuse users of screen readers and other assistive technologies because these users only hear the badge's content, not its visual styling. To a screen reader, a badge may sound like a random word or number tacked onto the end of a sentence, link, or button, which obscures its intended purpose.

Unless the context is clear - you should add extra, descriptive text that is `visually-hidden` but available to screen readers.

### Examples

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { SiBadgeComponent } from '@siemens/element-ng/badge';

@Component({
  selector: 'app-sample',
  imports: [SiBadgeComponent],
  templateUrl: './badges.html',
  host: {
    class: 'p-5 background-1'
  }
})
export class SampleComponent {}
```

Template:

```html
<div class="mb-5">
  <span class="badge bg-default">Default</span>
  <span class="badge bg-secondary">Secondary</span>
  <span class="badge bg-inverse">Inverse</span>
  <span class="badge bg-default">This is the max width of pill badge</span>
</div>
<div class="mb-5">
  <si-badge icon="element-face-neutral">Default</si-badge>
  <si-badge type="inverse" icon="element-sound-off">Inverse</si-badge>
  <si-badge icon="element-break">This is the max width of pill badge</si-badge>
</div>
<div class="mb-5">
  <span class="badge bg-info">Information</span>
  <span class="badge bg-success">Success</span>
  <span class="badge bg-warning">Warning</span>
  <span class="badge bg-danger">Danger</span>
  <span class="badge bg-critical">Critical</span>
  <span class="badge bg-caution">Caution</span>
</div>
<div class="mb-5">
  <span class="badge bg-info-emphasis">Information</span>
  <span class="badge bg-success-emphasis">Success</span>
  <span class="badge bg-warning-emphasis">Warning</span>
  <span class="badge bg-danger-emphasis">Danger</span>
  <span class="badge bg-critical-emphasis">Critical</span>
  <span class="badge bg-caution-emphasis">Caution</span>
</div>
<div class="mb-5">
  <si-badge type="info" icon="element-validation-information">Information</si-badge>
  <si-badge type="success" icon="element-validation-success">Success</si-badge>
  <si-badge type="warning" icon="element-validation-warning">Warning</si-badge>
  <si-badge type="danger" icon="element-validation-issue">Danger</si-badge>
  <si-badge type="critical" icon="element-validation-issue">Critical</si-badge>
  <si-badge type="caution" icon="element-validation-caution">Caution</si-badge>
</div>
<div class="mb-5">
  <si-badge type="info-emphasis" icon="element-validation-information">Information</si-badge>
  <si-badge type="success-emphasis" icon="element-validation-success">Success</si-badge>
  <si-badge type="warning-emphasis" icon="element-validation-warning">Warning</si-badge>
  <si-badge type="danger-emphasis" icon="element-validation-issue">Danger</si-badge>
  <si-badge type="critical-emphasis" icon="element-validation-issue">Critical</si-badge>
  <si-badge type="caution-emphasis" icon="element-validation-caution">Caution</si-badge>
</div>
<div class="mb-5">
  <span class="badge bg-default">1</span>
  <span class="badge bg-secondary">2</span>
  <span class="badge bg-info">13</span>
  <span class="badge bg-success">3</span>
  <span class="badge bg-warning">5</span>
  <span class="badge bg-caution">11</span>
  <span class="badge bg-danger">7</span>
  <span class="badge bg-critical">7</span>
  <span class="badge bg-inverse">17+</span>
</div>
<div class="mb-5">
  <si-badge type="success" icon="element-up-4">1.8%</si-badge>
  <si-badge type="success" icon="element-up-1-filled">2.9%</si-badge>
  <si-badge type="info" icon="element-ai">AI generated insights</si-badge>
</div>
<div class="mb-5">
  <si-badge type="danger" icon="element-down-4">1.8%</si-badge>
  <si-badge type="danger" icon="element-down-1-filled">2.9%</si-badge>
  <si-badge type="warning" icon="element-battery-low">Battery low</si-badge>
  <si-badge type="caution" icon="element-installer">Maintenance</si-badge>
</div>
<div class="mb-5">
  <i role="status" aria-label="notifications" class="icon element-alarm-filled badge-dot"></i>
</div>
<div class="mb-5" role="status" aria-label="8 notifications">
  <i class="icon element-alarm-filled"></i>
  <span class="badge-text" aria-hidden="true">8</span>
</div>
<div role="status" aria-label="More than 99 notifications">
  <i class="icon element-alarm-filled"></i>
  <span class="badge-text" aria-hidden="true">99+</span>
</div>
```

### [SiBadgeComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/badge/si-badge.component.ts#L36-L47>)

**Kind:** component

**Selector:** `si-badge`

```
import { SiBadgeComponent } from '@siemens/element-ng/badge';
```

```
component SiBadgeComponent
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [icon](<https://github.com/siemens/element/blob/main/projects/element-ng/badge/si-badge.component.ts#L41-L41>) | `string \| undefined` | `''` | Optional icon |
| [type](<https://github.com/siemens/element/blob/main/projects/element-ng/badge/si-badge.component.ts#L46-L46>) | `BadgeType` | `'default'` | Badge display type. |

### Types Documentation

### [BadgeType](<https://github.com/siemens/element/blob/main/projects/element-ng/badge/si-badge.component.ts#L9-L18>)

**Kind:** type alias

```
import type { BadgeType } from '@siemens/element-ng/badge';
```

```
type BadgeType = | StatusType
  | 'default'
  | 'inverse'
  | 'info-emphasis'
  | 'success-emphasis'
  | 'warning-emphasis'
  | 'danger-emphasis'
  | 'critical-emphasis'
  | 'caution-emphasis'
```

### [StatusType](<https://github.com/siemens/element/blob/main/projects/element-ng/common/models/status-type.model.ts#L7-L7>)

**Kind:** type alias

```
import type { StatusType } from '@siemens/element-ng/common';
```

```
type StatusType = 'success' | 'info' | 'warning' | 'danger' | 'caution' | 'critical'
```
