# ion-searchbar

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

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

Searchbars represent a text field that can be used to search through a collection. They can be displayed inside of a toolbar or the main content. A searchbar should be used instead of an input to search lists.

## Basic Usage

**JavaScript**

```html
<ion-searchbar></ion-searchbar>
<ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
<ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
<ion-searchbar value="Value"></ion-searchbar>
<ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar></ion-searchbar>
<ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
<ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
<ion-searchbar value="Value"></ion-searchbar>
<ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

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

**React**

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';

function Example() {
  return (
    <>
      <IonSearchbar></IonSearchbar>
      <IonSearchbar placeholder="Custom Placeholder"></IonSearchbar>
      <IonSearchbar disabled={true} placeholder="Disabled"></IonSearchbar>
      <IonSearchbar value="Value"></IonSearchbar>
      <IonSearchbar animated={true} placeholder="Animated"></IonSearchbar>
    </>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-searchbar></ion-searchbar>
  <ion-searchbar placeholder="Custom Placeholder"></ion-searchbar>
  <ion-searchbar disabled="true" placeholder="Disabled"></ion-searchbar>
  <ion-searchbar value="Value"></ion-searchbar>
  <ion-searchbar animated="true" placeholder="Animated"></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>
```

## Search Icon

A search icon is displayed to the left of the input field in a searchbar. It can be customized to any [Ionicon](https://ionic.io/ionicons/).

**JavaScript**

```html
<ion-searchbar></ion-searchbar>
<ion-searchbar search-icon="search-circle" placeholder="Custom Search Icon"></ion-searchbar>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar></ion-searchbar>
<ion-searchbar search-icon="search-circle" placeholder="Custom Search Icon"></ion-searchbar>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { searchCircle } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonSearchbar],
})
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({ searchCircle });
  }
}
```

**React**

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { searchCircle } from 'ionicons/icons';

function Example() {
  return (
    <>
      <IonSearchbar></IonSearchbar>
      <IonSearchbar searchIcon={searchCircle} placeholder="Custom Search Icon"></IonSearchbar>
    </>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-searchbar></ion-searchbar>
  <ion-searchbar :search-icon="searchCircle" placeholder="Custom Search Icon"></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { searchCircle } from 'ionicons/icons';
</script>
```

## Clear Button

A clear button is displayed when a searchbar has a value or upon entering input in the searchbar's text field. Clicking on the clear button will erase the text field and the input will remain focused. By default, the clear button is set to show when focusing the searchbar, but it can be set to always show or never show. The icon inside of the clear button can also be customized to any [Ionicon](https://ionic.io/ionicons/).

**JavaScript**

```html
<ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
<ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
<ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
<ion-searchbar show-clear-button="always" clear-icon="trash-bin" value="Custom Clear Icon"></ion-searchbar>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
<ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
<ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
<ion-searchbar show-clear-button="always" clear-icon="trash-bin" value="Custom Clear Icon"></ion-searchbar>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { trashBin } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonSearchbar],
})
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({ trashBin });
  }
}
```

**React**

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { trashBin } from 'ionicons/icons';

function Example() {
  return (
    <>
      <IonSearchbar showClearButton="focus" value="Show on Focus"></IonSearchbar>
      <IonSearchbar showClearButton="always" value="Always Show"></IonSearchbar>
      <IonSearchbar showClearButton="never" value="Never Show"></IonSearchbar>
      <IonSearchbar showClearButton="always" clearIcon={trashBin} value="Custom Clear Icon"></IonSearchbar>
    </>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-searchbar show-clear-button="focus" value="Show on Focus"></ion-searchbar>
  <ion-searchbar show-clear-button="always" value="Always Show"></ion-searchbar>
  <ion-searchbar show-clear-button="never" value="Never Show"></ion-searchbar>
  <ion-searchbar show-clear-button="always" :clear-icon="trashBin" value="Custom Clear Icon"></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { trashBin } from 'ionicons/icons';
</script>
```

## Cancel Button

A cancel button can be enabled which will clear the input and lose the focus upon click. By default, cancel buttons are set to never show, but they can be set to always show or only show when focusing the searchbar. The cancel button is displayed as text in `ios` mode, and as an icon in `md` mode. Both the text and icon can be customized using different properties, with the icon accepting any [Ionicon](https://ionic.io/ionicons/).

**JavaScript**

```html
<ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
<ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
<ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
<ion-searchbar
  show-cancel-button="always"
  cancel-button-text="Custom Cancel"
  cancel-button-icon="trash"
  placeholder="Custom Cancel Button"
></ion-searchbar>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
<ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
<ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
<ion-searchbar
  show-cancel-button="always"
  cancel-button-text="Custom Cancel"
  cancel-button-icon="trash"
  placeholder="Custom Cancel Button"
></ion-searchbar>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

import { addIcons } from 'ionicons';
import { trash } from 'ionicons/icons';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonSearchbar],
})
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({ trash });
  }
}
```

**React**

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';
import { trash } from 'ionicons/icons';

function Example() {
  return (
    <>
      <IonSearchbar showCancelButton="focus" placeholder="Show on Focus"></IonSearchbar>
      <IonSearchbar showCancelButton="always" placeholder="Always Show"></IonSearchbar>
      <IonSearchbar showCancelButton="never" placeholder="Never Show"></IonSearchbar>
      <IonSearchbar
        showCancelButton="always"
        cancelButtonText="Custom Cancel"
        cancelButtonIcon={trash}
        placeholder="Custom Cancel Button"
      ></IonSearchbar>
    </>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-searchbar show-cancel-button="focus" placeholder="Show on Focus"></ion-searchbar>
  <ion-searchbar show-cancel-button="always" placeholder="Always Show"></ion-searchbar>
  <ion-searchbar show-cancel-button="never" placeholder="Never Show"></ion-searchbar>
  <ion-searchbar
    show-cancel-button="always"
    cancel-button-text="Custom Cancel"
    :cancel-button-icon="trash"
    placeholder="Custom Cancel Button"
  ></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
import { trash } from 'ionicons/icons';
</script>
```

## Searchbars in Toolbars

Searchbars are styled to look native when placed inside of a toolbar. In iOS, searchbars should be placed in their own toolbar, under a toolbar that contains the page title. In Material Design, searchbars are either persistently displayed in their own toolbar, or expand over a toolbar containing the page title.

**JavaScript**

```html
<ion-header>
  <ion-toolbar>
    <ion-title>Toolbar</ion-title>
  </ion-toolbar>
  <ion-toolbar>
    <ion-searchbar></ion-searchbar>
  </ion-toolbar>
</ion-header>
```

**Angular**

`src/app/example.component.html`

```html
<ion-header>
  <ion-toolbar>
    <ion-title>Toolbar</ion-title>
  </ion-toolbar>
  <ion-toolbar>
    <ion-searchbar></ion-searchbar>
  </ion-toolbar>
</ion-header>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonHeader, IonSearchbar, IonTitle, IonToolbar } from '@ionic/angular';

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

**React**

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

function Example() {
  return (
    <IonHeader>
      <IonToolbar>
        <IonTitle>Toolbar</IonTitle>
      </IonToolbar>
      <IonToolbar>
        <IonSearchbar></IonSearchbar>
      </IonToolbar>
    </IonHeader>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-header>
    <ion-toolbar>
      <ion-title>Toolbar</ion-title>
    </ion-toolbar>
    <ion-toolbar>
      <ion-searchbar></ion-searchbar>
    </ion-toolbar>
  </ion-header>
</template>

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

## Debounce

A debounce can be set on the searchbar in order to delay triggering the `ionInput` event. This is useful when querying data, as it can be used to wait to make a request instead of requesting the data each time a character is entered in the input.

**JavaScript**

```html
<ion-searchbar debounce="1000"></ion-searchbar>
<ion-list></ion-list>

<script>
  const searchbar = document.querySelector('ion-searchbar');
  const list = document.querySelector('ion-list');

  const data = [
    'Amsterdam',
    'Buenos Aires',
    'Cairo',
    'Geneva',
    'Hong Kong',
    'Istanbul',
    'London',
    'Madrid',
    'New York',
    'Panama City',
  ];
  let results = [...data];
  filterItems(results);

  searchbar.addEventListener('ionInput', handleInput);

  function handleInput(event) {
    const query = event.target.value.toLowerCase();
    results = data.filter((d) => d.toLowerCase().indexOf(query) > -1);
    filterItems(results);
  }

  function filterItems(results) {
    list.replaceChildren();

    let items = '';

    for (let i = 0; i < results.length; i++) {
      items += `
        <ion-item>
          <ion-label>${results[i]}</ion-label>
        </ion-item>
      `;
    }

    list.innerHTML = items;
  }
</script>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar [debounce]="1000" (ionInput)="handleInput($event)"></ion-searchbar>

<ion-list>
  @for (result of results; track result) {
  <ion-item>
    <ion-label>{{ result }}</ion-label>
  </ion-item>
  }
</ion-list>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonItem, IonLabel, IonList, IonSearchbar } from '@ionic/angular';

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
  styleUrls: ['example.component.css'],
  imports: [IonItem, IonLabel, IonList, IonSearchbar],
})
export class ExampleComponent {
  public data = [
    'Amsterdam',
    'Buenos Aires',
    'Cairo',
    'Geneva',
    'Hong Kong',
    'Istanbul',
    'London',
    'Madrid',
    'New York',
    'Panama City',
  ];
  public results = [...this.data];

  handleInput(event: Event) {
    const target = event.target as HTMLIonSearchbarElement;
    const query = target.value?.toLowerCase() || '';
    this.results = this.data.filter((d) => d.toLowerCase().includes(query));
  }
}
```

**React**

```tsx
import React, { useState } from 'react';
import { IonItem, IonList, IonSearchbar } from '@ionic/react';

function Example() {
  const data = [
    'Amsterdam',
    'Buenos Aires',
    'Cairo',
    'Geneva',
    'Hong Kong',
    'Istanbul',
    'London',
    'Madrid',
    'New York',
    'Panama City',
  ];
  let [results, setResults] = useState([...data]);

  const handleInput = (event: Event) => {
    let query = '';
    const target = event.target as HTMLIonSearchbarElement;
    if (target) query = target.value!.toLowerCase();

    setResults(data.filter((d) => d.toLowerCase().indexOf(query) > -1));
  };

  return (
    <>
      <IonSearchbar debounce={1000} onIonInput={(event) => handleInput(event)}></IonSearchbar>

      <IonList>
        {results.map((result) => (
          <IonItem>{result}</IonItem>
        ))}
      </IonList>
    </>
  );
}
export default Example;
```

**Vue**

```vue
<template>
  <ion-searchbar :debounce="1000" @ionInput="handleInput($event)"></ion-searchbar>

  <ion-list>
    <ion-item v-for="result in results">
      <ion-label>{{ result }}</ion-label>
    </ion-item>
  </ion-list>
</template>

<script setup lang="ts">
import { IonItem, IonList, IonSearchbar } from '@ionic/vue';
import { ref } from 'vue';

const data = [
  'Amsterdam',
  'Buenos Aires',
  'Cairo',
  'Geneva',
  'Hong Kong',
  'Istanbul',
  'London',
  'Madrid',
  'New York',
  'Panama City',
];
const results = ref(data);

const handleInput = (event) => {
  const query = event.target.value.toLowerCase();
  results.value = data.filter((d) => d.toLowerCase().indexOf(query) > -1);
};
</script>
```

## Theming

### Colors

**JavaScript**

```html
<ion-searchbar placeholder="Default"></ion-searchbar>
<ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
<ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
<ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
<ion-searchbar color="success" placeholder="Success"></ion-searchbar>
<ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
<ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
<ion-searchbar color="light" placeholder="Light"></ion-searchbar>
<ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
<ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar placeholder="Default"></ion-searchbar>
<ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
<ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
<ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
<ion-searchbar color="success" placeholder="Success"></ion-searchbar>
<ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
<ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
<ion-searchbar color="light" placeholder="Light"></ion-searchbar>
<ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
<ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

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

**React**

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';

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

**Vue**

```vue
<template>
  <ion-searchbar placeholder="Default"></ion-searchbar>
  <ion-searchbar color="primary" placeholder="Primary"></ion-searchbar>
  <ion-searchbar color="secondary" placeholder="Secondary"></ion-searchbar>
  <ion-searchbar color="tertiary" placeholder="Tertiary"></ion-searchbar>
  <ion-searchbar color="success" placeholder="Success"></ion-searchbar>
  <ion-searchbar color="warning" placeholder="Warning"></ion-searchbar>
  <ion-searchbar color="danger" placeholder="Danger"></ion-searchbar>
  <ion-searchbar color="light" placeholder="Light"></ion-searchbar>
  <ion-searchbar color="medium" placeholder="Medium"></ion-searchbar>
  <ion-searchbar color="dark" placeholder="Dark"></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>
```

### CSS Custom Properties

Searchbar uses scoped encapsulation, which means it will automatically scope its CSS by appending each of the styles with an additional class at runtime. Overriding scoped selectors in CSS requires a [higher specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) selector. Targeting the `ion-searchbar` for customization will not work, therefore we recommend adding a class and customizing it that way.

**JavaScript**

```html
<ion-searchbar show-cancel-button="focus" class="custom"></ion-searchbar>

<style>
  /* Scoped components require higher specificity to customize */
  ion-searchbar.custom {
    --background: #19422d;
    --color: #fff;
    --placeholder-color: #fff;
    --icon-color: #fff;
    --clear-button-color: #fff;

    --border-radius: 4px;
  }

  ion-searchbar.ios.custom {
    --cancel-button-color: #19422d;
  }

  ion-searchbar.md.custom {
    --cancel-button-color: #fff;
  }
</style>
```

**Angular**

`src/app/example.component.html`

```html
<ion-searchbar showCancelButton="focus" class="custom"></ion-searchbar>
```

`src/app/example.component.css`

```css
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
  --background: #19422d;
  --color: #fff;
  --placeholder-color: #fff;
  --icon-color: #fff;
  --clear-button-color: #fff;

  --border-radius: 4px;
}

ion-searchbar.ios.custom {
  --cancel-button-color: #19422d;
}

ion-searchbar.md.custom {
  --cancel-button-color: #fff;
}
```

`src/app/example.component.ts`

```ts
import { Component } from '@angular/core';
import { IonSearchbar } from '@ionic/angular';

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

**React**

`src/main.tsx`

```tsx
import React from 'react';
import { IonSearchbar } from '@ionic/react';

import './main.css';

function Example() {
  return <IonSearchbar showCancelButton="focus" className="custom"></IonSearchbar>;
}
export default Example;
```

`src/main.css`

```css
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
  --background: #19422d;
  --color: #fff;
  --placeholder-color: #fff;
  --icon-color: #fff;
  --clear-button-color: #fff;

  --border-radius: 4px;
}

ion-searchbar.ios.custom {
  --cancel-button-color: #19422d;
}

ion-searchbar.md.custom {
  --cancel-button-color: #fff;
}
```

**Vue**

```vue
<template>
  <ion-searchbar showCancelButton="focus" class="custom"></ion-searchbar>
</template>

<script setup lang="ts">
import { IonSearchbar } from '@ionic/vue';
</script>

<style scoped>
/* Scoped components require higher specificity to customize */
ion-searchbar.custom {
  --background: #19422d;
  --color: #fff;
  --placeholder-color: #fff;
  --icon-color: #fff;
  --clear-button-color: #fff;

  --border-radius: 4px;
}

ion-searchbar.ios.custom {
  --cancel-button-color: #19422d;
}

ion-searchbar.md.custom {
  --cancel-button-color: #fff;
}
</style>
```

## Keyboard Display

### Android

By default, tapping the input will cause the keyboard to appear with a magnifying glass icon on the submit button. You can optionally set the `inputmode` property to `"search"`, which will change the icon from a magnifying glass to a carriage return.

### iOS

By default, tapping the input will cause the keyboard to appear with the text "return" on a gray submit button. You can optionally set the `inputmode` property to `"search"`, which will change the text from "return" to "go", and change the button color from gray to blue. Alternatively, you can wrap the `ion-searchbar` in a `form` element with an `action` property. This will cause the keyboard to appear with a blue submit button that says "search".

## Interfaces

### SearchbarChangeEventDetail

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

### SearchbarCustomEvent

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 SearchbarCustomEvent extends CustomEvent {
  detail: SearchbarChangeEventDetail;
  target: HTMLIonSearchbarElement;
}
```

## Properties

### animated

**Description**: If `true`, enable searchbar animation.

**Attribute**: `animated`

**Type**: `boolean`

**Default**: `false`

### autocapitalize

**Description**: Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. Available options: `"off"`, `"none"`, `"on"`, `"sentences"`, `"words"`, `"characters"`.

**Attribute**: `autocapitalize`

**Type**: `string`

**Default**: `'off'`

### autocomplete

**Description**: Set the input's autocomplete property.

**Attribute**: `autocomplete`

**Type**: `"additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday" | "bday-day" | "bday-month" | "bday-year" | "cc-additional-name" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "email" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "impp" | "language" | "name" | "new-password" | "nickname" | "off" | "on" | "one-time-code" | "organization" | "organization-title" | "photo" | "postal-code" | "sex" | "street-address" | "tel" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-national" | "transaction-amount" | "transaction-currency" | "url" | "username"`

**Default**: `'off'`

### autocorrect

**Description**: Set the input's autocorrect property.

**Attribute**: `autocorrect`

**Type**: `boolean`

**Default**: `false`

### cancelButtonIcon

**Description**: Set the cancel button icon. Only applies to `md` mode. Defaults to `arrow-back-sharp`.

**Attribute**: `cancel-button-icon`

**Type**: `string`

**Default**: `config.get('backButtonIcon', arrowBackSharp) as string`

### cancelButtonText

**Description**: Set the cancel button text. Only applies to `ios` mode.

**Attribute**: `cancel-button-text`

**Type**: `string`

**Default**: `'Cancel'`

### clearIcon

**Description**: Set the clear icon. Defaults to `close-circle` for `ios` and `close-sharp` for `md`.

**Attribute**: `clear-icon`

**Type**: `string | undefined`

**Default**: `undefined`

### 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`

### debounce

**Description**: Set the amount of time, in milliseconds, to wait to trigger the `ionInput` event after each keystroke.

**Attribute**: `debounce`

**Type**: `number | undefined`

**Default**: `undefined`

### disabled

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

**Attribute**: `disabled`

**Type**: `boolean`

**Default**: `false`

### enterkeyhint

**Description**: A hint to the browser for which enter key to display. Possible values: `"enter"`, `"done"`, `"go"`, `"next"`, `"previous"`, `"search"`, and `"send"`.

**Attribute**: `enterkeyhint`

**Type**: `"done" | "enter" | "go" | "next" | "previous" | "search" | "send" | undefined`

**Default**: `undefined`

### inputmode

**Description**: A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`.

**Attribute**: `inputmode`

**Type**: `"decimal" | "email" | "none" | "numeric" | "search" | "tel" | "text" | "url" | undefined`

**Default**: `undefined`

### maxlength

**Description**: This attribute specifies the maximum number of characters that the user can enter.

**Attribute**: `maxlength`

**Type**: `number | undefined`

**Default**: `undefined`

### minlength

**Description**: This attribute specifies the minimum number of characters that the user can enter.

**Attribute**: `minlength`

**Type**: `number | undefined`

**Default**: `undefined`

### 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`

### name

**Description**: If used in a form, set the name of the control, which is submitted with the form data.

**Attribute**: `name`

**Type**: `string`

**Default**: `this.inputId`

### placeholder

**Description**: Set the input's placeholder. `placeholder` can accept either plaintext or HTML as a string. To display characters normally reserved for HTML, they must be escaped. For example `<Ionic>` would become `&lt;Ionic&gt;` For more information: [Security Documentation](https://ionicframework.com/docs/faq/security)

**Attribute**: `placeholder`

**Type**: `string`

**Default**: `'Search'`

### searchIcon

**Description**: The icon to use as the search icon. Defaults to `search-outline` in `ios` mode and `search-sharp` in `md` mode.

**Attribute**: `search-icon`

**Type**: `string | undefined`

**Default**: `undefined`

### showCancelButton

**Description**: Sets the behavior for the cancel button. Defaults to `"never"`. Setting to `"focus"` shows the cancel button on focus. Setting to `"never"` hides the cancel button. Setting to `"always"` shows the cancel button regardless of focus state.

**Attribute**: `show-cancel-button`

**Type**: `"always" | "focus" | "never"`

**Default**: `'never'`

### showClearButton

**Description**: Sets the behavior for the clear button. Defaults to `"focus"`. Setting to `"focus"` shows the clear button on focus if the input is not empty. Setting to `"never"` hides the clear button. Setting to `"always"` shows the clear button regardless of focus state, but only if the input is not empty.

**Attribute**: `show-clear-button`

**Type**: `"always" | "focus" | "never"`

**Default**: `'always'`

### spellcheck

**Description**: If `true`, enable spellcheck on the input.

**Attribute**: `spellcheck`

**Type**: `boolean`

**Default**: `false`

### type

**Description**: Set the type of the input.

**Attribute**: `type`

**Type**: `"email" | "number" | "password" | "search" | "tel" | "text" | "url"`

**Default**: `'search'`

### value

**Description**: the value of the searchbar.

**Attribute**: `value`

**Type**: `null | string | undefined`

**Default**: `''`

## Events

| Name | Description | Bubbles |
| --- | --- | --- |
| `ionBlur` | Emitted when the input loses focus. | `true` |
| `ionCancel` | Emitted when the cancel button is clicked. | `true` |
| `ionChange` | The `ionChange` event is fired for `<ion-searchbar>` elements when the user modifies the element's value. Unlike the `ionInput` event, the `ionChange` event is not necessarily fired for each alteration to an element's value. The `ionChange` event is fired when the value has been committed by the user. This can happen when the element loses focus or when the "Enter" key is pressed. `ionChange` can also fire when clicking the clear or cancel buttons. This event will not emit when programmatically setting the `value` property. | `true` |
| `ionClear` | Emitted when the clear input button is clicked. | `true` |
| `ionFocus` | Emitted when the input has focus. | `true` |
| `ionInput` | Emitted when the `value` of the `ion-searchbar` element has changed. | `true` |

## Methods

### getInputElement

**Description**: Returns the native `<input>` element used under the hood.

**Signature**: `getInputElement() => Promise<HTMLInputElement>`

### setFocus

**Description**: Sets focus on the native `input` in `ion-searchbar`. Use this method instead of the global `input.focus()`. Developers who wish to focus an input when a page enters should call `setFocus()` in the `ionViewDidEnter()` lifecycle method. Developers who wish to focus an input when an overlay is presented should call `setFocus` after `didPresent` has resolved. See [managing focus](/docs/developing/managing-focus.md) for more information.

**Signature**: `setFocus() => Promise<void>`

## CSS Shadow Parts

No CSS shadow parts available for this component.

## CSS Custom Properties

**iOS**

| Name | Description |
| --- | --- |
| `--background` | Background of the searchbar input |
| `--border-radius` | Border radius of the searchbar input |
| `--box-shadow` | Box shadow of the searchbar input |
| `--cancel-button-color` | Color of the searchbar cancel button |
| `--clear-button-color` | Color of the searchbar clear button |
| `--color` | Color of the searchbar text |
| `--icon-color` | Color of the searchbar icon |
| `--placeholder-color` | Color of the searchbar placeholder |
| `--placeholder-font-style` | Font style of the searchbar placeholder |
| `--placeholder-font-weight` | Font weight of the searchbar placeholder |
| `--placeholder-opacity` | Opacity of the searchbar placeholder |

**MD**

| Name | Description |
| --- | --- |
| `--background` | Background of the searchbar input |
| `--border-radius` | Border radius of the searchbar input |
| `--box-shadow` | Box shadow of the searchbar input |
| `--cancel-button-color` | Color of the searchbar cancel button |
| `--clear-button-color` | Color of the searchbar clear button |
| `--color` | Color of the searchbar text |
| `--icon-color` | Color of the searchbar icon |
| `--placeholder-color` | Color of the searchbar placeholder |
| `--placeholder-font-style` | Font style of the searchbar placeholder |
| `--placeholder-font-weight` | Font weight of the searchbar placeholder |
| `--placeholder-opacity` | Opacity of the searchbar placeholder |

## Slots

No slots available for this component.
