# ion-segment

URL: https://ionicframework.com/docs/api/segment

**Encapsulation**: [shadow](/docs/reference/glossary.md#shadow)

Segments display a group of related buttons, sometimes known as segmented controls, in a horizontal row. They can be displayed inside of a toolbar or the main content.

Their functionality is similar to tabs, where selecting one will deselect all others. Segments are useful for toggling between different views inside of the content. Tabs should be used instead of a segment when clicking on a control should navigate between pages.

## Basic Usage

Segments consist of [segment buttons](/docs/api/segment-button.md) with a `value` property on each button. Set the `value` property on the segment to match the value of a button to select that button. Segments can also be disabled to prevent users from interacting with them.

**JavaScript**

```html
<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

<ion-segment disabled="true" value="disabled">
  <ion-segment-button value="disabled">
    <ion-label>Disabled</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

**Angular**

`src/app/example.component.html`

```html
<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>

<ion-segment [disabled]="true" value="disabled">
  <ion-segment-button value="disabled">
    <ion-label>Disabled</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}
```

**React**

```tsx
import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

function Example() {
  return (
    <>
      <IonSegment value="default">
        <IonSegmentButton value="default">
          <IonLabel>Default</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>

      <IonSegment disabled={true} value="disabled">
        <IonSegmentButton value="disabled">
          <IonLabel>Disabled</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-segment value="default">
    <ion-segment-button value="default">
      <ion-label>Default</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>

  <ion-segment :disabled="true" value="disabled">
    <ion-segment-button value="disabled">
      <ion-label>Disabled</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>
```

## Scrollable Segments

Segments are not scrollable by default. Each segment button has a fixed width, and the width is determined by dividing the number of segment buttons by the screen width. This ensures that each segment button can be displayed on the screen without having to scroll. As a result, some segment buttons with longer labels may get cut off. To avoid this we recommend either using a shorter label or switching to a scrollable segment by setting the `scrollable` property to `true`. This will cause the segment to scroll horizontally, but will allow each segment button to have a variable width.

**JavaScript**

`index.html`

```html
<ion-segment scrollable="true" value="heart">
  <ion-segment-button value="home">
    <ion-icon name="home"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="heart">
    <ion-icon name="heart"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="pin">
    <ion-icon name="pin"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="star">
    <ion-icon name="star"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="call">
    <ion-icon name="call"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="globe">
    <ion-icon name="globe"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="basket">
    <ion-icon name="basket"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="barbell">
    <ion-icon name="barbell"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="trash">
    <ion-icon name="trash"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="person">
    <ion-icon name="person"></ion-icon>
  </ion-segment-button>
</ion-segment>
```

`index.ts`

```ts
import { defineCustomElements } from '@ionic/core/loader';

import { addIcons } from 'ionicons';
import { barbell, basket, call, globe, heart, home, person, pin, star, trash } from 'ionicons/icons';

/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';

/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';

/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';

/**
 * Ionic Dark Palette
 * -----------------------------------------------------
 * For more information, please see:
 * https://ionicframework.com/docs/theming/dark-mode
 */

// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';

/* Theme variables */
import './theme/variables.css';

/**
 * On Ionicons 7.2+ these icons
 * get mapped to a kebab-case key.
 * Alternatively, developers can do:
 * addIcons({ 'barbell': barbell, 'basket': basket, 'call': call, 'globe': globe,
 * 'heart': heart, 'home': home, 'person': person, 'pin': pin, 'star': star, 'trash': trash });
 */
addIcons({ barbell, basket, call, globe, heart, home, person, pin, star, trash });

defineCustomElements();
```

**Angular**

`src/app/example.component.html`

```html
<ion-segment [scrollable]="true" value="heart">
  <ion-segment-button value="home">
    <ion-icon name="home"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="heart">
    <ion-icon name="heart"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="pin">
    <ion-icon name="pin"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="star">
    <ion-icon name="star"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="call">
    <ion-icon name="call"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="globe">
    <ion-icon name="globe"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="basket">
    <ion-icon name="basket"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="barbell">
    <ion-icon name="barbell"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="trash">
    <ion-icon name="trash"></ion-icon>
  </ion-segment-button>
  <ion-segment-button value="person">
    <ion-icon name="person"></ion-icon>
  </ion-segment-button>
</ion-segment>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { barbell, basket, call, globe, heart, home, person, pin, star, trash } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonIcon, IonSegment, IonSegmentButton],
})
export class ExampleComponent {
  constructor() {
    /**
     * Any icons you want to use in your application
     * can be registered in app.component.ts and then
     * referenced by name anywhere in your application.
     */
    addIcons({ barbell, basket, call, globe, heart, home, person, pin, star, trash });
  }
}
```

**React**

```tsx
import React from 'react';
import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/react';
import { home, heart, pin, star, call, globe, basket, barbell, trash, person } from 'ionicons/icons';

function Example() {
  return (
    <IonSegment scrollable={true} value="heart">
      <IonSegmentButton value="home">
        <IonIcon icon={home}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="heart">
        <IonIcon icon={heart}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="pin">
        <IonIcon icon={pin}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="star">
        <IonIcon icon={star}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="call">
        <IonIcon icon={call}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="globe">
        <IonIcon icon={globe}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="basket">
        <IonIcon icon={basket}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="barbell">
        <IonIcon icon={barbell}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="trash">
        <IonIcon icon={trash}></IonIcon>
      </IonSegmentButton>
      <IonSegmentButton value="person">
        <IonIcon icon={person}></IonIcon>
      </IonSegmentButton>
    </IonSegment>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-segment :scrollable="true" value="heart">
    <ion-segment-button value="home">
      <ion-icon :icon="home"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="heart">
      <ion-icon :icon="heart"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="pin">
      <ion-icon :icon="pin"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="star">
      <ion-icon :icon="star"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="call">
      <ion-icon :icon="call"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="globe">
      <ion-icon :icon="globe"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="basket">
      <ion-icon :icon="basket"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="barbell">
      <ion-icon :icon="barbell"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="trash">
      <ion-icon :icon="trash"></ion-icon>
    </ion-segment-button>
    <ion-segment-button value="person">
      <ion-icon :icon="person"></ion-icon>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonIcon, IonSegment, IonSegmentButton } from '@ionic/vue';
  import { home, heart, pin, star, call, globe, basket, barbell, trash, person } from 'ionicons/icons';
</script>
```

## Segments in Toolbars

**JavaScript**

```html
<ion-header>
  <ion-toolbar>
    <ion-segment value="all">
      <ion-segment-button value="all">
        <ion-label>All</ion-label>
      </ion-segment-button>
      <ion-segment-button value="favorites">
        <ion-label>Favorites</ion-label>
      </ion-segment-button>
    </ion-segment>
  </ion-toolbar>
</ion-header>
```

**Angular**

`src/app/example.component.html`

```html
<ion-header>
  <ion-toolbar>
    <ion-segment value="all">
      <ion-segment-button value="all">
        <ion-label>All</ion-label>
      </ion-segment-button>
      <ion-segment-button value="favorites">
        <ion-label>Favorites</ion-label>
      </ion-segment-button>
    </ion-segment>
  </ion-toolbar>
</ion-header>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonToolbar } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonHeader, IonLabel, IonSegment, IonSegmentButton, IonToolbar],
})
export class ExampleComponent {}
```

**React**

```tsx
import React from 'react';
import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonTitle, IonToolbar } from '@ionic/react';

function Example() {
  return (
    <IonHeader>
      <IonToolbar>
        <IonSegment value="all">
          <IonSegmentButton value="all">
            <IonLabel>All</IonLabel>
          </IonSegmentButton>
          <IonSegmentButton value="favorites">
            <IonLabel>Favorites</IonLabel>
          </IonSegmentButton>
        </IonSegment>
      </IonToolbar>
    </IonHeader>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-header>
    <ion-toolbar>
      <ion-segment value="all">
        <ion-segment-button value="all">
          <ion-label>All</ion-label>
        </ion-segment-button>
        <ion-segment-button value="favorites">
          <ion-label>Favorites</ion-label>
        </ion-segment-button>
      </ion-segment>
    </ion-toolbar>
  </ion-header>
</template>

<script setup lang="ts">
  import { IonHeader, IonLabel, IonSegment, IonSegmentButton, IonTitle, IonToolbar } from '@ionic/vue';
</script>
```

## Swipeable Segments

Each [segment button](/docs/api/segment-button.md) can be associated with a [segment content](/docs/api/segment-content.md) element that will be displayed when the segment is active. With this approach, each segment's content can be swiped or scrolled between and the segment will be updated to reflect the currently visible content.

**Warning**

If no initial `value` is assigned to the `ion-segment` when using swipeable segments, the segment will default to the value of the first segment button. Segment buttons cannot be disabled when used with swipeable segments.

**JavaScript**

```html
<ion-segment>
  <ion-segment-button value="first" content-id="first">
    <ion-label>First</ion-label>
  </ion-segment-button>
  <ion-segment-button value="second" content-id="second">
    <ion-label>Second</ion-label>
  </ion-segment-button>
  <ion-segment-button value="third" content-id="third">
    <ion-label>Third</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment-view>
  <ion-segment-content id="first">First</ion-segment-content>
  <ion-segment-content id="second">Second</ion-segment-content>
  <ion-segment-content id="third">Third</ion-segment-content>
</ion-segment-view>

<style>
  ion-segment-view {
    height: 150px;
  }

  ion-segment-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  ion-segment-content:nth-of-type(1) {
    background: lightpink;
  }
  ion-segment-content:nth-of-type(2) {
    background: lightblue;
  }
  ion-segment-content:nth-of-type(3) {
    background: lightgreen;
  }
</style>
```

**Angular**

`src/app/example.component.html`

```html
<ion-segment>
  <ion-segment-button value="first" content-id="first">
    <ion-label>First</ion-label>
  </ion-segment-button>
  <ion-segment-button value="second" content-id="second">
    <ion-label>Second</ion-label>
  </ion-segment-button>
  <ion-segment-button value="third" content-id="third">
    <ion-label>Third</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment-view>
  <ion-segment-content id="first">First</ion-segment-content>
  <ion-segment-content id="second">Second</ion-segment-content>
  <ion-segment-content id="third">Third</ion-segment-content>
</ion-segment-view>
```

`src/app/example.component.css`

```css
ion-segment-view {
  height: 150px;
}

ion-segment-content {
  display: flex;
  align-items: center;
  justify-content: center;
}
ion-segment-content:nth-of-type(1) {
  background: lightpink;
}
ion-segment-content:nth-of-type(2) {
  background: lightblue;
}
ion-segment-content:nth-of-type(3) {
  background: lightgreen;
}
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView],
})
export class ExampleComponent {}
```

**React**

`src/main.css`

```css
ion-segment-view {
  height: 150px;
}

ion-segment-content {
  display: flex;
  align-items: center;
  justify-content: center;
}
ion-segment-content:nth-of-type(1) {
  background: lightpink;
}
ion-segment-content:nth-of-type(2) {
  background: lightblue;
}
ion-segment-content:nth-of-type(3) {
  background: lightgreen;
}
```

`src/main.tsx`

```tsx
import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <>
      <IonSegment value="first">
        <IonSegmentButton value="first" contentId="first">
          <IonLabel>First</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="second" contentId="second">
          <IonLabel>Second</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="third" contentId="third">
          <IonLabel>Third</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegmentView>
        <IonSegmentContent id="first">First</IonSegmentContent>
        <IonSegmentContent id="second">Second</IonSegmentContent>
        <IonSegmentContent id="third">Third</IonSegmentContent>
      </IonSegmentView>
    </>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-segment>
    <ion-segment-button value="first" content-id="first">
      <ion-label>First</ion-label>
    </ion-segment-button>
    <ion-segment-button value="second" content-id="second">
      <ion-label>Second</ion-label>
    </ion-segment-button>
    <ion-segment-button value="third" content-id="third">
      <ion-label>Third</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment-view>
    <ion-segment-content id="first">First</ion-segment-content>
    <ion-segment-content id="second">Second</ion-segment-content>
    <ion-segment-content id="third">Third</ion-segment-content>
  </ion-segment-view>
</template>

<style>
  ion-segment-view {
    height: 150px;
  }

  ion-segment-content {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  ion-segment-content:nth-of-type(1) {
    background: lightpink;
  }
  ion-segment-content:nth-of-type(2) {
    background: lightblue;
  }
  ion-segment-content:nth-of-type(3) {
    background: lightgreen;
  }
</style>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView } from '@ionic/vue';
</script>
```

## Theming

### Colors

**JavaScript**

```html
<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="primary" value="primary">
  <ion-segment-button value="primary">
    <ion-label>Primary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="secondary" value="secondary">
  <ion-segment-button value="secondary">
    <ion-label>Secondary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="tertiary" value="tertiary">
  <ion-segment-button value="tertiary">
    <ion-label>Tertiary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="success" value="success">
  <ion-segment-button value="success">
    <ion-label>Success</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="warning" value="warning">
  <ion-segment-button value="warning">
    <ion-label>Warning</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="danger" value="danger">
  <ion-segment-button value="danger">
    <ion-label>Danger</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="light" value="light">
  <ion-segment-button value="light">
    <ion-label>Light</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="medium" value="medium">
  <ion-segment-button value="medium">
    <ion-label>Medium</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="dark" value="dark">
  <ion-segment-button value="dark">
    <ion-label>Dark</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

**Angular**

`src/app/example.component.html`

```html
<ion-segment value="default">
  <ion-segment-button value="default">
    <ion-label>Default</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="primary" value="primary">
  <ion-segment-button value="primary">
    <ion-label>Primary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="secondary" value="secondary">
  <ion-segment-button value="secondary">
    <ion-label>Secondary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="tertiary" value="tertiary">
  <ion-segment-button value="tertiary">
    <ion-label>Tertiary</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="success" value="success">
  <ion-segment-button value="success">
    <ion-label>Success</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="warning" value="warning">
  <ion-segment-button value="warning">
    <ion-label>Warning</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="danger" value="danger">
  <ion-segment-button value="danger">
    <ion-label>Danger</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="light" value="light">
  <ion-segment-button value="light">
    <ion-label>Light</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="medium" value="medium">
  <ion-segment-button value="medium">
    <ion-label>Medium</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
<ion-segment color="dark" value="dark">
  <ion-segment-button value="dark">
    <ion-label>Dark</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}
```

**React**

```tsx
import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

function Example() {
  return (
    <>
      <IonSegment value="default">
        <IonSegmentButton value="default">
          <IonLabel>Default</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="primary" value="primary">
        <IonSegmentButton value="primary">
          <IonLabel>Primary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="secondary" value="secondary">
        <IonSegmentButton value="secondary">
          <IonLabel>Secondary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="tertiary" value="tertiary">
        <IonSegmentButton value="tertiary">
          <IonLabel>Tertiary</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="success" value="success">
        <IonSegmentButton value="success">
          <IonLabel>Success</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="warning" value="warning">
        <IonSegmentButton value="warning">
          <IonLabel>Warning</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="danger" value="danger">
        <IonSegmentButton value="danger">
          <IonLabel>Danger</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="light" value="light">
        <IonSegmentButton value="light">
          <IonLabel>Light</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="medium" value="medium">
        <IonSegmentButton value="medium">
          <IonLabel>Medium</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
      <IonSegment color="dark" value="dark">
        <IonSegmentButton value="dark">
          <IonLabel>Dark</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-segment value="default">
    <ion-segment-button value="default">
      <ion-label>Default</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="primary" value="primary">
    <ion-segment-button value="primary">
      <ion-label>Primary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="secondary" value="secondary">
    <ion-segment-button value="secondary">
      <ion-label>Secondary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="tertiary" value="tertiary">
    <ion-segment-button value="tertiary">
      <ion-label>Tertiary</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="success" value="success">
    <ion-segment-button value="success">
      <ion-label>Success</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="warning" value="warning">
    <ion-segment-button value="warning">
      <ion-label>Warning</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="danger" value="danger">
    <ion-segment-button value="danger">
      <ion-label>Danger</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="light" value="light">
    <ion-segment-button value="light">
      <ion-label>Light</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="medium" value="medium">
    <ion-segment-button value="medium">
      <ion-label>Medium</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
  <ion-segment color="dark" value="dark">
    <ion-segment-button value="dark">
      <ion-label>Dark</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>
```

### CSS Custom Properties

**JavaScript**

```html
<style>
  ion-segment {
    --background: #54dc98;
  }
</style>

<ion-segment value="custom">
  <ion-segment-button value="custom">
    <ion-label>Custom</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

**Angular**

`src/app/example.component.html`

```html
<ion-segment value="custom">
  <ion-segment-button value="custom">
    <ion-label>Custom</ion-label>
  </ion-segment-button>
  <ion-segment-button value="segment">
    <ion-label>Segment</ion-label>
  </ion-segment-button>
</ion-segment>
```

`src/app/example.component.css`

```css
ion-segment {
  --background: #54dc98;
}
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonLabel, IonSegment, IonSegmentButton],
})
export class ExampleComponent {}
```

**React**

`src/main.css`

```css
ion-segment {
  --background: #54dc98;
}
```

`src/main.tsx`

```tsx
import React from 'react';
import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/react';

import './main.css';

function Example() {
  return (
    <>
      <IonSegment value="custom">
        <IonSegmentButton value="custom">
          <IonLabel>Custom</IonLabel>
        </IonSegmentButton>
        <IonSegmentButton value="segment">
          <IonLabel>Segment</IonLabel>
        </IonSegmentButton>
      </IonSegment>
    </>
  );
}
export default Example;
```

**Vue**

```html
<template>
  <ion-segment value="custom">
    <ion-segment-button value="custom">
      <ion-label>Custom</ion-label>
    </ion-segment-button>
    <ion-segment-button value="segment">
      <ion-label>Segment</ion-label>
    </ion-segment-button>
  </ion-segment>
</template>

<script setup lang="ts">
  import { IonLabel, IonSegment, IonSegmentButton } from '@ionic/vue';
</script>

<style>
  ion-segment {
    --background: #54dc98;
  }
</style>
```

## Accessibility

### Keyboard Interactions

The component has full keyboard support for navigating between and selecting `ion-segment-button` elements. By default, keyboard navigation will only focus `ion-segment-button` elements, but you can use the `selectOnFocus` property to ensure that they get selected on focus as well. The following table details what each key does:

| Key | Description |
| --- | --- |
| ArrowRight | Focuses the next focusable element. |
| ArrowLeft | Focuses the previous focusable element. |
| Home | Focuses the first focusable element. |
| End | Focuses the last focusable element. |
| Space or Enter | Selects the element that is currently focused. |

## Interfaces

### SegmentChangeEventDetail

```typescript
interface SegmentChangeEventDetail {
  value?: string;
}
```

### SegmentCustomEvent

While not required, this interface can be used in place of the `CustomEvent` interface for stronger typing with Ionic events emitted from this component.

```typescript
interface SegmentCustomEvent extends CustomEvent {
  target: HTMLIonSegmentElement;
  detail: SegmentChangeEventDetail;
}
```

## Properties

### color

**Description**: The color to use from your application's color palette. Default options are: `"primary"`, `"secondary"`, `"tertiary"`, `"success"`, `"warning"`, `"danger"`, `"light"`, `"medium"`, and `"dark"`. For more information on colors, see [theming](/docs/theming/basics.md).

**Attribute**: `color`

**Type**: `"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined`

**Default**: `undefined`

### disabled

**Description**: If `true`, the user cannot interact with the segment.

**Attribute**: `disabled`

**Type**: `boolean`

**Default**: `false`

### mode

**Description**: The mode determines which platform styles to use. This is a [virtual property](/docs/core-concepts/fundamentals.md#virtual-properties) that is set once during initialization and will not update if you change its value after the initial render.

**Attribute**: `mode`

**Type**: `"ios" | "md"`

**Default**: `undefined`

### scrollable

**Description**: If `true`, the segment buttons will overflow and the user can swipe to see them. In addition, this will disable the gesture to drag the indicator between the buttons in order to swipe to see hidden buttons.

**Attribute**: `scrollable`

**Type**: `boolean`

**Default**: `false`

### selectOnFocus

**Description**: If `true`, navigating to an `ion-segment-button` with the keyboard will focus and select the element. If `false`, keyboard navigation will only focus the `ion-segment-button` element.

**Attribute**: `select-on-focus`

**Type**: `boolean`

**Default**: `false`

### swipeGesture

**Description**: If `true`, users will be able to swipe between segment buttons to activate them.

**Attribute**: `swipe-gesture`

**Type**: `boolean`

**Default**: `true`

### value

**Description**: the value of the segment.

**Attribute**: `value`

**Type**: `number | string | undefined`

**Default**: `undefined`

## Events

| Name | Description | Bubbles |
| --- | --- | --- |
| `ionChange` | Emitted when the value property has changed and any dragging pointer has been released from `ion-segment`. This event will not emit when programmatically setting the `value` property. | `true` |

## Methods

No public methods available for this component.

## CSS Shadow Parts

No CSS shadow parts available for this component.

## CSS Custom Properties

**iOS**

| Name | Description |
| --- | --- |
| `--background` | Background of the segment button |

**MD**

| Name | Description |
| --- | --- |
| `--background` | Background of the segment button |

## Slots

| Name | Description |
| --- | --- |
|  | The default slot |
