# Buttons

**Buttons** initiate actions and communicate their purpose through labels.

## Usage

Use buttons to trigger actions. Labels should clearly describe the purpose and effect of the action, such as Add, Save, or Delete.

There are three semantic types:

- **Default buttons** for standard actions such as Save or Submit.
- **Warning buttons** for cautious decisions such as Overwrite or Restart.
- **Danger buttons** for destructive actions such as Delete or Remove.

Each button also carries a visual weight:

- **Primary buttons** highlight the main action of the page or task.
- **Secondary buttons** for supporting actions.
- **Tertiary buttons** for low-priority or less prominent actions.

![Button](<../images/buttons.png>)

### Button link

A **button link** is a button styled as a [link](<https://element.siemens.io/components/buttons-menus/links/>).

Despite its link-like appearance, its primary distinction lies in its function: [Links](<https://element.siemens.io/components/buttons-menus/links/>), built with the `<a>` HTML element, are designed for navigation, whereas button links, created using the `<button>` HTML element, are intended to trigger actions. This distinction ensures correct semantics, accessibility, and behavior.

While visually similar to a tertiary button, button links work well in tight layouts or inline with text, where a regular button would be too bulky.

![Button link comparisson](<../images/button-link.png>)

### Best practices

- Use only one primary button per page.
- Ensure call-to-action labels are straightforward and concise.
- Use single-line text for button labels; avoid multi-line text.
- When truncating text, ensure at least three characters of the content remain visible.
- Use the loading button to indicate ongoing processes.
- Use `spacing-6` to define the space between buttons and other components/containers.

## Design

### Variants

Buttons support text, icon, or a combination of both.

![Button types](<../images/button-types.png>)

Icon-only buttons adapt their shape based on layout constraints and visual context.

**Circle buttons** are used when the button is placed inside a circular container (e.g., pills) or in unconstrained, free-form contexts for standalone actions (e.g., overlays, floating controls, wizard). The circular shape signals a self-contained action and visually separates it from structured layouts.

**Square buttons** are used in structured layouts where consistent alignment is required (e.g., inputs, tables, cards). The rectangular shape anchors the action to the surrounding layout and scales better when multiple actions are placed side by side.

![Button icon](<../images/button-icon.png>)

### Size

Buttons are available in three height variants:

- **Small** (24px) for compact areas such as inside input fields.
- **Default** (32px) for general use across most layouts.
- **Large** (40px) for high-visibility actions or spacious layouts.

### Button placement

The position and alignment of buttons is defined in relationship to their container. Buttons can be aligned right or center in relation to the parent container.

#### Related buttons

This is the case of two or more buttons that display related actions (e.g: save/cancel).

- Related buttons should all be the same width
- Spacing (margin) between related buttons is `spacing-s`

### Responsive grid

Typically, buttons are placed side by side. However, if the viewport becomes too narrow to display all the text label, buttons should be stacked following the responsive grid.

#### Text truncation

Text labels should be short and concise. When a long label cannot be avoided, truncate it with an ellipsis `(…)` at the end of the line. Only wrap the text when the full label is critical and truncation would cause loss of meaning.

## Code

Buttons are implemented using CSS classes on native HTML elements. Use `<button>` for actions and `<a>` for navigation. No Angular component is required.

### Usage

Apply the `.btn` base class together with a semantic variant such as `.btn-primary`. Always add `type="button"` to action buttons. Icon-only buttons must have an accessible name via `aria-label`, `title` or a visually hidden label.

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './buttons.html'
})
export class SampleComponent {
  disabled = false;
}
```

Template:

```html
<div class="d-flex flex-column p-5 h-100">
  <div class="mb-6">
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button type="button" class="btn btn-primary" [disabled]="disabled">Default</button>
      <button type="button" class="btn btn-warning" [disabled]="disabled">Warning</button>
      <button type="button" class="btn btn-danger" [disabled]="disabled">Danger</button>
      <button type="button" class="btn btn-ghost" [disabled]="disabled">Ghost</button>
      <button type="button" class="btn btn-secondary" [disabled]="disabled">Secondary</button>
      <button type="button" class="btn btn-secondary-warning" [disabled]="disabled">
        Warning
      </button>
      <button type="button" class="btn btn-secondary-danger" [disabled]="disabled">Danger</button>
      <button type="button" class="btn btn-secondary-ghost" [disabled]="disabled">Ghost</button>
      <button type="button" class="btn btn-tertiary" [disabled]="disabled">Tertiary</button>
      <button type="button" class="btn btn-tertiary-warning" [disabled]="disabled">
        Warning
      </button>
      <button type="button" class="btn btn-tertiary-danger" [disabled]="disabled">Danger</button>
      <button type="button" class="btn btn-tertiary-ghost" [disabled]="disabled">Ghost</button>
    </div>

    <h4 class="mb-4">Buttons with icons</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button type="button" class="btn btn-primary" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-ok"></i>Default
      </button>
      <button type="button" class="btn btn-warning" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-alarm"></i>Warning
      </button>
      <button type="button" class="btn btn-danger" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-delete"></i>Danger
      </button>
      <button type="button" class="btn btn-ghost" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-download"></i>Ghost
      </button>
      <button type="button" class="btn btn-secondary" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-upload"></i>Secondary
      </button>
      <button type="button" class="btn btn-tertiary" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-upload"></i>Tertiary
      </button>
    </div>

    <h4 class="mb-4">Input buttons</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button type="button" class="btn btn-input" [disabled]="disabled">Input</button>
      <button type="button" class="btn btn-input dropdown-toggle" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-calendar"></i>24.8.2023 - 31.8.2023
        <i aria-hidden="true" class="dropdown-caret icon element-down-2"></i>
      </button>
    </div>

    <h4 class="mb-4">Icon buttons</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button
        type="button"
        class="btn btn-icon btn-primary element-clock"
        aria-label="clock"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-warning element-bath"
        aria-label="bath"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-danger element-library"
        aria-label="library"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-ghost"
        aria-label="rocket"
        [disabled]="disabled"
      >
        <i aria-hidden="true" class="icon element-rocket"></i>
      </button>

      <button
        type="button"
        class="btn btn-icon btn-secondary element-badge"
        aria-label="secondary badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-secondary-warning element-badge"
        aria-label="secondary warning badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-secondary-danger element-badge"
        aria-label="secondary danger badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-secondary-ghost element-badge"
        aria-label="secondary ghost badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-tertiary element-badge"
        aria-label="tertiary badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-tertiary-warning element-badge"
        aria-label="tertiary warning badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-tertiary-danger element-badge"
        aria-label="tertiary danger badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-icon btn-tertiary-ghost element-badge"
        aria-label="tertiary ghost badge"
        [disabled]="disabled"
      ></button>
    </div>

    <h4 class="mb-4">Circle buttons</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button
        type="button"
        class="btn btn-circle btn-primary element-clock"
        aria-label="clock"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-warning element-bath"
        aria-label="bath"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-danger element-library"
        aria-label="library"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-ghost element-rocket"
        aria-label="rocket"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-secondary element-badge"
        aria-label="secondary badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-secondary-warning element-badge"
        aria-label="secondary warning badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-secondary-danger element-badge"
        aria-label="secondary danger badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-secondary-ghost element-badge"
        aria-label="secondary ghost badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-tertiary element-badge"
        aria-label="tertiary badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-tertiary-warning element-badge"
        aria-label="tertiary warning badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-tertiary-danger element-badge"
        aria-label="tertiary danger badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn btn-circle btn-tertiary-ghost element-badge"
        aria-label="tertiary ghost badge"
        [disabled]="disabled"
      ></button>

      <button
        type="button"
        class="btn-close btn-tertiary"
        aria-label="close"
        [disabled]="disabled"
      ></button>

      <button type="button" class="btn-close" aria-label="close" [disabled]="disabled"></button>
    </div>

    <h4 class="mb-4">Button sizing</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button type="button" class="btn btn-secondary btn-lg" [disabled]="disabled">Large</button>
      <button type="button" class="btn btn-secondary" [disabled]="disabled">Default</button>
      <button type="button" class="btn btn-secondary btn-sm" [disabled]="disabled">Small</button>
      <button type="button" class="btn btn-secondary btn-lg" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-rocket"></i>
        Large
      </button>
      <button type="button" class="btn btn-secondary" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-rocket"></i>
        Default
      </button>
      <button type="button" class="btn btn-secondary btn-sm" [disabled]="disabled">
        <i aria-hidden="true" class="icon element-rocket"></i>
        Small
      </button>
    </div>

    <h4 class="mb-4">Icon button sizing</h4>
    <div class="d-flex flex-wrap align-items-center gap-4 mb-6">
      <button
        type="button"
        class="btn btn-icon btn-lg btn-secondary element-minus"
        aria-label="default icon button"
        [disabled]="disabled"
      ></button>
      <button
        type="button"
        class="btn btn-icon btn-lg btn-circle btn-secondary element-plus"
        aria-label="default circle button"
        [disabled]="disabled"
      ></button>
      <button
        type="button"
        class="btn btn-icon btn-secondary element-minus"
        aria-label="default icon button"
        [disabled]="disabled"
      ></button>
      <button
        type="button"
        class="btn btn-icon btn-circle btn-secondary element-plus"
        aria-label="default circle button"
        [disabled]="disabled"
      ></button>
      <button
        type="button"
        class="btn btn-icon btn-sm btn-secondary element-minus"
        aria-label="small icon button"
        [disabled]="disabled"
      ></button>
      <button
        type="button"
        class="btn btn-icon btn-circle btn-sm btn-secondary element-plus"
        aria-label="small circle button"
        [disabled]="disabled"
      ></button>
    </div>

    <h4 class="mb-4">Button links</h4>
    <div class="d-flex flex-wrap align-items-center gap-4">
      <a class="btn btn-primary" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Primary Link
      </a>
      <a class="btn btn-warning" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Warning Link
      </a>
      <a class="btn btn-danger" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Danger Link
      </a>
      <a class="btn btn-ghost" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Ghost Link
      </a>
      <a class="btn btn-secondary" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Secondary Link
      </a>
      <a class="btn btn-tertiary" href="#">
        <i aria-hidden="true" class="icon element-link"></i>Tertiary Link
      </a>
    </div>
  </div>

  <div class="d-inline-block background-1 p-5 mt-auto rounded-3 e2e-ignore">
    <div class="form-check mb-2 form-switch">
      <input
        type="checkbox"
        class="form-check-input"
        role="switch"
        id="backdrop-switch"
        [checked]="disabled"
        (change)="disabled = !disabled"
      />
      <label for="backdrop-switch" class="form-check-label">Disable all buttons</label>
    </div>
  </div>
</div>
```

### Navigation buttons

When a navigation link needs the visual appearance of a button, such as the primary call to action on an info page, apply button classes to an `<a>` element.

```
<a class="btn btn-primary" href="https://siemens.com">Go back</a>
```

### Placement

Use [flex](<https://element.siemens.io/fundamentals/styles/flex/>) and [grid](<https://element.siemens.io/fundamentals/layouts/grid/>) utilities to handle long labels and adapt button layouts to available space:

- **Wrapping labels:** Without truncation, labels wrap onto additional lines as the available width decreases. Keep labels concise, and wrap only when users need to see the full label.
- **Truncated labels:** Use `.text-truncate` to keep a long label on one line. Set a minimum width if needed to keep enough of the label visible.
- **Responsive layout:** Use grid columns such as `.col-sm-6` to stack buttons vertically below 576px and place them side by side at 576px and above. See [Flexbox grid](<https://element.siemens.io/fundamentals/layouts/grid/>).
- **Dialog actions:** Use `.modal-footer` to right-align dialog actions and provide consistent spacing.
- **Custom footers:** Use flex utilities such as `.d-flex`, `.flex-wrap`, `.justify-content-end`, and `.gap-6` to create a similar layout or customize the alignment. See [Flex utilities](<https://element.siemens.io/fundamentals/styles/flex/>).

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './buttons-placement.html'
})
export class SampleComponent {}
```

Template:

```html
<div class="p-5">
  <section class="row mb-6">
    <div class="col-12 col-xl-7">
      <div class="d-flex gap-3 background-1 p-4 rounded-3">
        <button type="button" class="btn btn-warning">
          Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
        </button>
        <button type="button" class="btn btn-primary">
          Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
        </button>
      </div>
    </div>
  </section>

  <section class="row mb-6">
    <div class="col-12 col-xl-7">
      <h4 class="mb-4">With text truncation</h4>
      <div class="d-flex gap-3 background-1 p-4 rounded-3">
        <button type="button" class="btn btn-warning d-inline text-truncate">
          Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
        </button>
        <button type="button" class="btn btn-primary d-inline text-truncate">
          Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
        </button>
      </div>
    </div>
  </section>

  <section class="row mb-6">
    <div class="col-12 col-xl-7">
      <h4 class="mb-4"
        >Responsive grid: vertical layout
        <code class="background-1 mx-2 py-1 px-2 rounded-2 text-primary fw-normal"
          >&lt; 576px</code
        ></h4
      >
      <div class="background-1 p-4 rounded-3">
        <div class="row g-3">
          <div class="col-sm-6">
            <button type="button" class="btn btn-warning w-100 d-inline text-truncate">
              Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
            </button>
          </div>
          <div class="col-sm-6">
            <button type="button" class="btn btn-primary w-100 d-inline text-truncate">
              Longcat is a long cat is longer than the cat, but longcat is longer than the other cat
            </button>
          </div>
        </div>
      </div>
    </div>
  </section>

  <section class="row mb-6">
    <div class="col-12 col-xl-7">
      <h4 class="mb-4"
        >Modal footer layout using
        <code class="background-1 mx-2 py-1 px-2 rounded-2 text-primary fw-normal"
          >.modal-footer</code
        ></h4
      >
      <div class="modal-footer background-1 rounded-3">
        <button type="button" class="btn btn-secondary">Cancel</button>
        <button type="button" class="btn btn-danger">Discard</button>
        <button type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </section>

  <section class="row g-4">
    <div class="col-12 col-xl-7">
      <h4 class="mb-4">Footer with flex utilities</h4>
      <div class="d-flex flex-wrap justify-content-end gap-6 background-1 p-8 rounded-3">
        <button type="button" class="btn btn-secondary">Cancel</button>
        <button type="button" class="btn btn-danger">Discard</button>
        <button type="button" class="btn btn-primary">Save</button>
      </div>
    </div>
  </section>
</div>
```
