# Breadcrumb

**Breadcrumbs** help users to see their current location in relation to the rest of the website or application.

## Usage

Breadcrumbs display the user's location within a hierarchical structure, showing the path from the highest-level entity (root) to the current page or content, one step at a time.

They typically begin with the root page and progress to the active page, helping users understand where they are and navigate back to higher levels.

![Breadcrumb](<../images/breadcrumb.png>)

### When to use

- Use breadcrumbs when the user is most likely to have landed on the page from an external source.
- Use for applications that have a large amount of content organized in a hierarchy of more than two levels.

### Best practices

- Avoid using breadcrumbs on single-level sites or applications without a meaningful hierarchy.
- All breadcrumb items should be clickable.
- Breadcrumbs are secondary navigation, they should never replace the primary navigation.
- Use consistent naming that matches page titles or navigation labels.

## Design

### Elements

A breadcrumb consists of the following elements:

![Breadcrumb](<../images/breadcrumb-usage-construction.png>)

1. **Root element:** Highest entity level, displayed with an icon or a text.
2. **Entity name:** An entity represents a section or page within the product or page. Entity names use a button link that uses the section or page title to link to that section or page.
3. **Separator:** Provides a visual distinction between individual entities using the same font as the rest of the breadcrumb (not icons).
4. **Current page or content:** Indicates the current position. It's not a link.

### Root element

The root element can either be the default icon `element-breadcrumb-root` or a meaningful text, like `Startpage`.

![Breadcrumb variants](<../images/breadcrumb-usage-variants.png>)

### Responsive behavior

The default rule is to show as much of the path as possible in the available real estate. Entities will be truncated if the available space is not sufficient to show the entire breadcrumb.

### Truncation

![Breadcrumb](<../images/breadcrumb-usage-truncation.png>)

Super long entity names are truncated.

![Breadcrumb](<../images/breadcrumb-usage-truncation-dropdown.png>)

Truncated entity labels show their full text in a tooltip on hover or keyboard focus. Clicking the label navigates directly to the entity.

### Long breadcrumb

![Breadcrumb](<../images/breadcrumb-usage-responsive-behavior.png>)

When a path contains more levels of entities that can be displayed, the breadcrumb auto-collapses and uses ellipses to indicate more information. It's best practice to show at least the first and last entity when collapsing. Users open a menu containing the hidden breadcrumb items by clicking on the ellipses. Selecting an item navigates to that entity and closes the menu. The menu also closes on an outside click or by pressing Escape, returning focus to the ellipses button.

## Code

The first entry will be used as the root element and won't show the title but will be represented as an icon.

The `items` parameter takes an array of `BreadcrumbItem` entries. They contain a `title` and `link` property. The `link` property can be an array or a string and will be used as a `routerLink`.

### Usage

```
import { SiBreadcrumbRouterComponent } from '@siemens/element-ng/breadcrumb-router';

@Component({
  imports: [SiBreadcrumbRouterComponent,...]
})
```

#### Example

Component:

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

@Component({
  selector: 'app-sample',
  imports: [SiBreadcrumbModule],
  templateUrl: './si-breadcrumb.html',
  host: { class: 'p-5' }
})
export class SampleComponent {}
```

Template:

```html
<h2>Root as icon</h2>
<si-breadcrumb
  ariaLabel="root as icon breadcrumbs"
  [items]="[
    { title: 'Root', link: 'root' },
    { title: 'Level 1', link: ['root', 'level1'] },
    { title: 'Level 2 with a really long title', link: ['root', 'level1', 'level2'] },
    { title: 'Level 3', link: ['root', 'level1', 'level2', 'level3'] },
    { title: 'Level 4', link: ['root', 'level1', 'level2', 'level3', 'level4'] },
    { title: 'Level 5', link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5'] },
    {
      title: 'Level 6',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6']
    },
    {
      title: 'Level 7',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6', 'level7']
    },
    {
      title: 'Level 8 thisHasALongNonSeparableTitle',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6', 'level7', 'level8']
    },
    { title: 'Level 9', link: '.' }
  ]"
/>

<br />
<h2>Root as text</h2>
<si-breadcrumb
  ariaLabel="root as text breadcrumbs"
  [items]="[
    { title: 'Root', link: 'root' },
    { title: 'Level 1', link: ['root', 'level1'] },
    { title: 'Level 2 with a really long title', link: ['root', 'level1', 'level2'] },
    { title: 'Level 3', link: ['root', 'level1', 'level2', 'level3'] },
    { title: 'Level 4', link: ['root', 'level1', 'level2', 'level3', 'level4'] },
    { title: 'Level 5', link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5'] },
    {
      title: 'Level 6',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6']
    },
    {
      title: 'Level 7',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6', 'level7']
    },
    {
      title: 'Level 8 thisHasALongNonSeparableTitle',
      link: ['root', 'level1', 'level2', 'level3', 'level4', 'level5', 'level6', 'level7', 'level8']
    },
    { title: 'Level 9', link: '.' }
  ]"
  [showRootAsText]="true"
/>
```

### Breadcrumb Router

The `si-breadcrumb-router` component displays a breadcrumb according to the Angular router hierarchy of the current route. The breadcrumb titles and links are configurable by enriching the Angular route configuration with addition data. The component uses the default implementation `SiBreadcrumbDefaultResolverService` of the `SiBreadcrumbResolverService` interface, which reads the router configuration and provides the `BreadcrumbItem` objects. Using the injector token `SI_BREADCRUMB_RESOLVER_SERVICE` you can provide your own `SiBreadcrumbResolverService` implementation.

```
import { SI_BREADCRUMB_RESOLVER_SERVICE, SiBreadcrumbRouterComponent } from '@siemens/element-ng/breadcrumb-router';

...

@Component({
  imports: [
    ...
    SiBreadcrumbRouterComponent,
  ],
  providers: [
    {
      provide: SI_BREADCRUMB_RESOLVER_SERVICE,
      useClass: YourBreadcrumbResolverService,
    }
  ]
  ...
})
```

When using the default resolver service you need to enrich the Angular route configuration with breadcrumb information. The default resolver iterates through the route hierarchy to construct the breadcrumb items. The breadcrumb item title is taken from the path element or from a `title` property of the `data` configuration object. For a custom configuration that deviate from the route hierarchy, use a `siBreadcrumb` object in the `data` object that provides the complete breadcrumb item information for that route. Configure `title` and an optional `link`. The following example shows the variations:

- `title` configuration in `data` object
- `title` with route parameter configuration in `data` object
- `title` and `link` configuration in nested `siBreadcrumb` object

The `title` can also be a translation key and gets translated. Unfortunately, translation does currently not work in combination with route parameter.

```
import { Route } from '@angular/router';

export const routes: Route[] = [
  {
    path: 'test',
    data: {
      title: 'Test' // Title is displayed in the breadcrumb
    },
    children: [
      {
        path: ':id',
        data: {
          title: 'Test - {id}' // id will be resolved with the current parameter value
        }
      }
    ]
  },
  {
    path: 'test/sub-test',
    data: {
      /*
       * In this scenario the automatic calculation of the route is broken because
       * test/sub-test is handled as one UrlSegment. Therefore, only one breadcrumb
       * link would be rendered. Providing the links manually solves this problem.
       * It is not possible to define wildcards in the link names here.
       */
      siBreadcrumb: [
        { title: 'Test', link: '/test' },
        { title: 'Sub-Test', link: '/test/sub-test' }
      ]
    }
  },
  {
    path: 'protocol/:idprotocol/run/:idrun',
    component: RunComponent,
    data: {
      siBreadcrumb: [
        { title: 'Protocol ({idprotocol})', link: 'protocol/:idprotocol' },
        { title: 'Run ({idrun})' } // current route is used if no path is provided
      ]
    }
  }
];
```

The `siBreadcrumb` object is an array of `BreadcrumbRouterLink` objects.

### [BreadcrumbRouterLink](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L30-L39>)

**Kind:** interface

```
import type { BreadcrumbRouterLink } from '@siemens/element-ng/breadcrumb-router';
```

Defines the title and link of a breadcrumb item in a route configuration and compatible to [BreadcrumbItem](<index.html#t:BreadcrumbItem>).

```
{
  path: 'user-manual',
  component: UserManualComponent,
  data: {
    siBreadcrumb: [
      { title: 'USER_MANUAL.HEADING', link: '/main/user-manual' }
    ]
  }
}
```

```
interface BreadcrumbRouterLink
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [link](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L34-L34>) (optional) | `string` | Angular router link for the breadcrumb item. |
| [title](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L38-L38>) | `TranslatableString` | Breadcrumb item title that will be translated. |

See [Angular docs](<https://angular.dev/api/router/Resolve>) to learn how to resolve route data with the Angular router resolvers.

#### Example

Component:

```typescript
/**
 * Copyright (c) Siemens 2016 - 2026
 * SPDX-License-Identifier: MIT
 */
import { Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute, Route, Router, RouterLink, RouterOutlet } from '@angular/router';
import { SiBreadcrumbRouterComponent } from '@siemens/element-ng/breadcrumb-router';
import { provideExampleRoutes } from '@siemens/live-preview';

@Component({
  selector: 'app-home',
  imports: [RouterLink],
  template: '<a routerLink="catalog">Browse catalog</a>'
})
export class HomeComponent {}

@Component({
  selector: 'app-catalog',
  imports: [RouterOutlet],
  template: '<router-outlet />'
})
export class CatalogComponent {}

@Component({
  selector: 'app-catalog-overview',
  imports: [RouterLink],
  template: `
    <nav aria-label="Catalog pages" class="d-flex gap-4">
      <a routerLink="products">Products</a>
      <a routerLink="orders">Orders</a>
    </nav>
  `
})
export class CatalogOverviewComponent {}

@Component({
  selector: 'app-products',
  imports: [RouterLink],
  template: '<p>Products</p><a routerLink="../orders">View orders</a>'
})
export class ProductsComponent {}

@Component({
  selector: 'app-orders',
  imports: [RouterLink],
  template: '<p>Orders</p><a routerLink="../products">View products</a>'
})
export class OrdersComponent {}

export const ROUTES: Route[] = [
  { path: '', component: HomeComponent, pathMatch: 'full' },
  {
    path: 'catalog',
    component: CatalogComponent,
    data: { title: 'Catalog' },
    children: [
      { path: '', component: CatalogOverviewComponent, pathMatch: 'full' },
      { path: 'products', component: ProductsComponent, data: { title: 'Products' } },
      { path: 'orders', component: OrdersComponent, data: { title: 'Orders' } }
    ]
  }
];

@Component({
  selector: 'app-sample',
  imports: [RouterOutlet, SiBreadcrumbRouterComponent],
  templateUrl: './si-breadcrumb-router.html',
  providers: [provideExampleRoutes(ROUTES)],
  host: { class: 'p-5' }
})
export class SampleComponent implements OnInit {
  private readonly route = inject(ActivatedRoute);
  private readonly router = inject(Router);

  ngOnInit(): void {
    this.router.navigate(['catalog', 'products'], { relativeTo: this.route });
  }
}
```

Template:

```html
<si-breadcrumb-router />
<div class="mt-4">
  <router-outlet />
</div>
```

### Custom Breadcrumb Resolver

There are scenarios where the default resolver is not sufficient. In those cases you can write a custom resolver like this:

```
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot } from '@angular/router';
import { BreadcrumbItem } from '@siemens/element-ng/breadcrumb';
import { SiBreadcrumbDefaultResolverService } from '@siemens/element-ng/breadcrumb-router';
import { Observable } from 'rxjs';

@Injectable()
export class CustomBreadcrumbResolverService extends SiBreadcrumbDefaultResolverService {
  resolve(route: ActivatedRouteSnapshot): BreadcrumbItem[] | Observable<BreadcrumbItem[]> {
    return super
      .resolve(route)
      .map((link: BreadcrumbItem) => ({ ...link, title: rewriteName(link.name) }));
  }
}
```

The resolver uses the following type:

### [SiBreadcrumbResolverService](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L44-L46>)

**Kind:** interface

```
import type { SiBreadcrumbResolverService } from '@siemens/element-ng/breadcrumb-router';
```

Service interface to resolve the breadcrumb items on the base of a route.

```
interface SiBreadcrumbResolverService
```

#### Methods

##### resolve

[Source for resolve](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L45-L45>)

```
resolve(route: ActivatedRouteSnapshot): BreadcrumbItem[] | Observable<BreadcrumbItem[]>
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [route](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.model.ts#L45-L45>) | `ActivatedRouteSnapshot` |  |  |

**Returns:** [BreadcrumbItem](<index.html#t:BreadcrumbItem>)`[] | `[Observable](<https://rxjs.dev/api/index/class/Observable>)`<`[BreadcrumbItem](<index.html#t:BreadcrumbItem>)`[]>`

Afterwards you need to provide the custom resolver, instead of the default resolver, in your `app.module.ts`:

```
import { SI_BREADCRUMB_RESOLVER_SERVICE, SiBreadcrumbRouterComponent } from '@siemens/element-ng/breadcrumb-router';

...

@Component({
  imports: [
    ...
    SiBreadcrumbRouterComponent,
  ],
  providers: [
    {
      provide: SI_BREADCRUMB_RESOLVER_SERVICE,
      useClass: CustomBreadcrumbResolverService,
    }
  ]
  ...
})

export class AppComponent {
}
```

### [SiBreadcrumbComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/si-breadcrumb.component.ts#L65-L237>)

**Kind:** component

**Selector:** `si-breadcrumb`

```
import { SiBreadcrumbComponent } from '@siemens/element-ng/breadcrumb';
```

```
component SiBreadcrumbComponent implements OnChanges, OnDestroy
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [ariaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/si-breadcrumb.component.ts#L82-L82>) | `TranslatableString` | `` $localize`:@@SI_BREADCRUMB:Breadcrumb navigation` `` | Aria label for the main breadcrumb navigation. Needed for a11y. |
| [items](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/si-breadcrumb.component.ts#L67-L67>) (required) | `BreadcrumbItem[]` |  | Array of breadcrumb items. |
| [showRootAsText](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/si-breadcrumb.component.ts#L73-L73>) | `boolean` | `false` | Shows the "root" route as the provided title string instead of an icon. |

### [SiBreadcrumbRouterComponent](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.component.ts#L28-L136>)

**Kind:** component

**Selector:** `si-breadcrumb-router`

```
import { SiBreadcrumbRouterComponent } from '@siemens/element-ng/breadcrumb-router';
```

```
component SiBreadcrumbRouterComponent implements OnInit, OnDestroy
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [ariaLabel](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb-router/si-breadcrumb-router.component.ts#L37-L37>) | `TranslatableString` | `` $localize`:@@SI_BREADCRUMB_ROUTER_LABEL:breadcrumb` `` | Aria label for the main breadcrumb navigation. Needed for a11y. |

### Types Documentation

### [BreadcrumbItem](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/breadcrumb-item.model.ts#L12-L14>)

**Kind:** interface

```
import type { BreadcrumbItem } from '@siemens/element-ng/breadcrumb';
```

Item that should be displayed in a breadcrumb. As input, we expect an optional title and link, which can be an URL or array of URL segments.

```
interface BreadcrumbItem extends Link
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [action](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L42-L42>) (optional, inherited) | `string \| ((param?: any) => void \| any)` | A function that will be invoked when clicking on the menu item. When passed as a string, use together with SiLinkActionService to receive events. This is meant for repetitive things in lists/tables/etc.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L50-L50>) (optional, inherited) | `boolean` | A boolean that lets the link know whether it is disabled or not.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [href](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L22-L22>) (optional, inherited) | `string` | Defines a href URI that the menu item will be linked to. Will be used to set the href attribute of the a element. Will only be used if link and function is not set.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [isActive](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L46-L46>) (optional, inherited) | `boolean` | A boolean that lets the link know whether it is active or not. It is useful when action() is executed instead of link route.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [link](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L32-L32>) (optional, inherited) | `string \| any[]` | Defines the link of the menu item within the application using the angular router link concept. Accepts an array of `any` as per \[routerLink API definition\][https://angular.dev/api/router/RouterLink](<https://angular.dev/api/router/RouterLink>).<br><br>Inherited from [Link](<index.html#t:Link>) |
| [navigationExtras](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L36-L36>) (optional, inherited) | `NavigationExtras` | The navigation extras provide additional routing options when using the router link.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [target](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L27-L27>) (optional, inherited) | `string` | The target attribute specifies where to open the linked document. If no target is specified, the link will open in the current tab.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [title](<https://github.com/siemens/element/blob/main/projects/element-ng/breadcrumb/breadcrumb-item.model.ts#L13-L13>) | `string` | The title of the menu item. Can be either the title to be displayed or the translation key.<br><br>Inherited from [Link](<index.html#t:Link>) |
| [tooltip](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L17-L17>) (optional, inherited) | `TranslatableString` | The optional tooltip of the link. Can be either the text to be displayed or the translation key.<br><br>Inherited from [Link](<index.html#t:Link>) |

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

Represents a translatable string. This can either be a translation key, e.g. `ACTIONS.EDIT` that will be automatically translated when displayed on the UI or a pre-translated string, e.g. `Edit`. Equivalent to a normal string in usage and functionality.

```
type TranslatableString = string & Translatable
```

### [Link](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L8-L51>)

**Kind:** interface

```
import type { Link } from '@siemens/element-ng/link';
```

```
interface Link
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [action](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L42-L42>) (optional) | `string \| ((param?: any) => void \| any)` | A function that will be invoked when clicking on the menu item. When passed as a string, use together with SiLinkActionService to receive events. This is meant for repetitive things in lists/tables/etc. |
| [disabled](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L50-L50>) (optional) | `boolean` | A boolean that lets the link know whether it is disabled or not. |
| [href](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L22-L22>) (optional) | `string` | Defines a href URI that the menu item will be linked to. Will be used to set the href attribute of the a element. Will only be used if link and function is not set. |
| [isActive](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L46-L46>) (optional) | `boolean` | A boolean that lets the link know whether it is active or not. It is useful when action() is executed instead of link route. |
| [link](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L32-L32>) (optional) | `string \| any[]` | Defines the link of the menu item within the application using the angular router link concept. Accepts an array of `any` as per \[routerLink API definition\][https://angular.dev/api/router/RouterLink](<https://angular.dev/api/router/RouterLink>). |
| [navigationExtras](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L36-L36>) (optional) | `NavigationExtras` | The navigation extras provide additional routing options when using the router link. |
| [target](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L27-L27>) (optional) | `string` | The target attribute specifies where to open the linked document. If no target is specified, the link will open in the current tab. |
| [title](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L12-L12>) (optional) | `TranslatableString` | The title of the menu item. Can be either the title to be displayed or the translation key. |
| [tooltip](<https://github.com/siemens/element/blob/main/projects/element-ng/link/link.model.ts#L17-L17>) (optional) | `TranslatableString` | The optional tooltip of the link. Can be either the text to be displayed or the translation key. |
