# HTML table

**HTML tables** are based on the native HTML table element and are intended for simple, mostly static data.

## Usage

HTML table is the lowest-complexity option. Because it is based on the native HTML table element, it comes with some inherent limitations.

- The header is not sticky when vertical scrolling is used.
- Column widths cannot be resized by users.
- Pagination is not supported.
- There is no built-in support for DOM or data virtualization, unlike ngx-datatable.
- Performance degrades with larger datasets, depending on DOM complexity and hardware.

![HTML table](<../images/HTML-table.png>)

### When to use

- Use it when the dataset is small.
- When the content is mostly read-only.
- When advanced interactions are not required.

## Code

Element styles native HTML tables with CSS classes. Apply the `.table` class to a `<table>` element.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {
  elementAlarm,
  elementAlarmBackgroundFilled,
  elementAlarmFilled,
  elementAlarmTick,
  elementCalculatedValue,
  elementCancelFilled,
  elementConfigValue,
  elementDown2,
  elementMaintenanceFilled,
  elementManualFilled,
  elementTransient,
  elementPhysicalInput
} from '@siemens/element-icons';
import { SiFormItemComponent } from '@siemens/element-ng/form';
import { addIcons, SiIconComponent } from '@siemens/element-ng/icon';

@Component({
  selector: 'app-sample',
  imports: [FormsModule, SiFormItemComponent, SiIconComponent],
  templateUrl: './html-table.html',
  host: { class: 'p-5' }
})
export class SampleComponent {
  readonly icons = addIcons({
    elementAlarm,
    elementAlarmBackgroundFilled,
    elementAlarmFilled,
    elementAlarmTick,
    elementCalculatedValue,
    elementCancelFilled,
    elementConfigValue,
    elementDown2,
    elementMaintenanceFilled,
    elementManualFilled,
    elementTransient,
    elementPhysicalInput
  });
  useHover = false;
  useSmallTable = false;
}
```

Template:

```html
<div class="container-fluid">
  <div class="row">
    <div class="col">
      <table class="table" [class.table-sm]="useSmallTable" [class.table-hover]="useHover">
        <thead>
          <tr>
            <th scope="col" class="text-center">
              <input
                type="checkbox"
                class="form-check-input float-none align-middle"
                aria-label="all selected"
              />
            </th>
            <th scope="col" class="text-center"
              ><si-icon
                aria-label="Expand all"
                class="icon"
                icon="element-expand-all"
                role="button"
            /></th>
            <th scope="col" class="text-center">Type</th>
            <th scope="col">Data point</th>
            <th scope="col" class="text-center">Quality</th>
            <th scope="col" class="text-center">Mode</th>
            <th scope="col" class="text-center">Event</th>
            <th scope="col">Value</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td class="text-center">
              <input
                type="checkbox"
                class="form-check-input float-none align-middle"
                aria-label="selected"
              />
            </td>
            <td class="text-center">
              <button
                type="button"
                class="btn btn-tertiary btn-circle"
                title="open dropdown"
                aria-label="open dropdown"
              >
                <si-icon [icon]="icons.elementDown2" />
              </button>
            </td>
            <td class="text-center">
              <si-icon class="icon" [icon]="icons.elementConfigValue" />
            </td>
            <td>
              <span class="si-h5">Cooling coil device mode</span><br /><span
                class="si-body text-secondary"
                >B1'Flr_1'RSegm1'HVAC</span
              >
            </td>
            <td class="text-center">
              <si-icon class="icon text-secondary" [icon]="icons.elementTransient" />
            </td>
            <td class="text-center">
              <si-icon class="icon status-warning" [icon]="icons.elementMaintenanceFilled" />
            </td>
            <td class="text-center">
              <si-icon class="icon" [icon]="icons.elementAlarm" />
            </td>
            <td class="si-body">
              <input type="text" class="form-control" value="50%" aria-label="value" disabled />
            </td>
          </tr>
          <tr>
            <td class="text-center">
              <input
                type="checkbox"
                class="form-check-input float-none align-middle"
                aria-label="selected"
              />
            </td>
            <td class="text-center">
              <button
                type="button"
                class="btn btn-tertiary btn-circle"
                title="open dropdown"
                aria-label="open dropdown"
              >
                <si-icon [icon]="icons.elementDown2" />
              </button>
            </td>
            <td class="text-center">
              <si-icon class="icon" [icon]="icons.elementPhysicalInput" />
            </td>
            <td class="si-h5">Cooling coil cooling request</td>
            <td class="text-center"></td>
            <td class="text-center">
              <si-icon class="icon status-danger" [icon]="icons.elementManualFilled" />
            </td>
            <td class="text-center"></td>
            <td class="si-body">
              <select class="form-select" aria-label="value" disabled>
                <option value="">Control Mode</option>
              </select>
            </td>
          </tr>
          <tr class="table-active">
            <td class="text-center">
              <input
                type="checkbox"
                class="form-check-input float-none align-middle"
                aria-label="selected"
              />
            </td>
            <td class="text-center">
              <button
                type="button"
                class="btn btn-tertiary btn-circle"
                title="open dropdown"
                aria-label="open dropdown"
              >
                <si-icon [icon]="icons.elementDown2" />
              </button>
            </td>
            <td class="text-center">
              <si-icon class="icon" [icon]="icons.elementPhysicalInput" />
            </td>
            <td class="si-h5">Cooling coil dehumidification request</td>
            <td class="text-center"></td>
            <td class="text-center">
              <si-icon class="icon status-warning" [icon]="icons.elementManualFilled" />
            </td>
            <td class="text-center">
              <si-icon class="icon status-danger" [icon]="icons.elementAlarmFilled" />
            </td>
            <td class="si-body">
              <input type="text" class="form-control" value="50%" aria-label="value" disabled />
            </td>
          </tr>
          <tr>
            <td class="text-center">
              <input
                type="checkbox"
                class="form-check-input float-none align-middle"
                aria-label="selected"
              />
            </td>
            <td class="text-center">
              <button
                type="button"
                class="btn btn-tertiary btn-circle"
                title="open dropdown"
                aria-label="open dropdown"
              >
                <si-icon [icon]="icons.elementDown2" />
              </button>
            </td>
            <td class="text-center">
              <si-icon class="icon" [icon]="icons.elementCalculatedValue" />
            </td>
            <td class="si-h5">Cooling coil available for cooling</td>
            <td class="text-center">
              <si-icon class="icon status-danger" [icon]="icons.elementCancelFilled" />
            </td>
            <td class="text-center"></td>
            <td class="text-center">
              <span class="icon icon-stack">
                <si-icon class="status-danger" [icon]="icons.elementAlarmBackgroundFilled" />
                <si-icon class="text-secondary" [icon]="icons.elementAlarmTick" />
              </span>
            </td>
            <td class="si-body">
              <input type="text" class="form-control" value="50%" aria-label="value" disabled />
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
  <div class="row e2e-ignore">
    <div class="col">
      <div class="card">
        <div class="card-header">Settings</div>
        <div class="card-body">
          <div class="mb-6 row">
            <label class="col-form-label col-md-2" for="use-small-table">Condensed rows</label>
            <div class="col-md-10">
              <si-form-item label="Check to apply the table-sm class for condensed row height.">
                <input type="checkbox" class="form-check-input" [(ngModel)]="useSmallTable" />
              </si-form-item>
            </div>
          </div>
          <div class="mb-6 row">
            <label class="col-form-label col-md-2" for="use-hover">Hoverable rows</label>
            <div class="col-md-10">
              <si-form-item label="Check to apply the table-hover class.">
                <input type="checkbox" class="form-check-input" [(ngModel)]="useHover" />
              </si-form-item>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
```

### Usage

Use semantic table markup with a caption, table headers, and table body. Add `scope="col"` to column headers and `scope="row"` to row headers so assistive technologies can associate headers with their cells.

```
<table class="table">
  <caption>Device status</caption>
  <thead>
    <tr>
      <th scope="col">Device</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Cooling unit</th>
      <td>Operational</td>
    </tr>
  </tbody>
</table>
```

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './html-table-basic.html',
  host: { class: 'p-5' }
})
export class SampleComponent {}
```

Template:

```html
<table class="table">
  <thead>
    <tr>
      <th scope="col">Device</th>
      <th scope="col">Status</th>
      <th scope="col">Last updated</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Cooling unit</th>
      <td>Operational</td>
      <td>10:30</td>
    </tr>
    <tr>
      <th scope="row">Ventilation unit</th>
      <td>Operational</td>
      <td>10:28</td>
    </tr>
  </tbody>
</table>
```

### Variants

Add `.table-sm` to use condensed rows. Add `.table-striped` to distinguish alternating body rows, and `.table-hover` to provide hover feedback for body rows.

Apply `.table-active` to a row or cell to highlight it. Use `.table-success`, `.table-info`, `.table-warning`, or `.table-danger` on a row or cell to communicate its status.

```
<table class="table table-sm table-striped table-hover">
  <!-- Table content -->
</table>

<tr class="table-active">
  <!-- Table cells -->
</tr>

<tr class="table-warning">
  <!-- Table cells -->
</tr>
```

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './html-table-variants.html',
  host: { class: 'p-5' }
})
export class SampleComponent {}
```

Template:

```html
<table class="table table-sm table-striped table-hover">
  <thead>
    <tr>
      <th scope="col">Device</th>
      <th scope="col">Status</th>
      <th scope="col">Last updated</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Cooling unit</th>
      <td>Operational</td>
      <td>10:30</td>
    </tr>
    <tr class="table-active">
      <th scope="row">Ventilation unit</th>
      <td>Selected</td>
      <td>10:28</td>
    </tr>
    <tr class="table-warning">
      <th scope="row">Heating unit</th>
      <td>Maintenance required</td>
      <td>10:20</td>
    </tr>
  </tbody>
</table>
```

### Captions

Captions are displayed below the table by default. Add `.caption-top` to the `<table>` element to display the caption above it.

```
<table class="table caption-top">
  <caption>Device status</caption>
  <!-- Table content -->
</table>
```

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './html-table-caption.html',
  host: { class: 'p-5' }
})
export class SampleComponent {}
```

Template:

```html
<table class="table caption-top">
  <caption>Device status</caption>
  <thead>
    <tr>
      <th scope="col">Device</th>
      <th scope="col">Status</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Cooling unit</th>
      <td>Operational</td>
    </tr>
  </tbody>
</table>
```

### Responsive tables

Wrap a wide table in `.table-responsive` to allow horizontal scrolling. Use a breakpoint variant such as `.table-responsive-md` to enable scrolling only below that breakpoint.

```
<div class="table-responsive">
  <table class="table">
    <!-- Table content -->
  </table>
</div>
```

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  templateUrl: './html-table-responsive.html',
  host: { class: 'p-5' }
})
export class SampleComponent {}
```

Template:

```html
<div class="table-responsive" tabindex="0" aria-label="Scrollable device status table">
  <table class="table">
    <thead>
      <tr>
        <th scope="col">Device</th>
        <th scope="col">Status</th>
        <th scope="col">Last updated</th>
        <th scope="col">Location</th>
        <th scope="col">Operator</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Cooling unit</th>
        <td>Operational</td>
        <td>10:30</td>
        <td>Building A</td>
        <td>Alex Smith</td>
      </tr>
      <tr>
        <th scope="row">Ventilation unit</th>
        <td>Operational</td>
        <td>10:28</td>
        <td>Building B</td>
        <td>Jordan Lee</td>
      </tr>
    </tbody>
  </table>
</div>
```
