> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Selecting tabs

> Select or deselect bottom tab bar items from your website with the JavaScript Bridge, or automatically with URL rules.

Use tab selection to control which bottom tab bar item appears active in your Median app. Tabs are automatically selected when users tap them, but you can also update the active tab programmatically with the Median JavaScript Bridge or by matching page URLs with tab selection rules.

This is useful when:

* A user navigates to a tab page from a link, push notification, or redirect.
* Your website uses custom navigation instead of only the native bottom tab bar.
* You need to highlight the correct tab for dynamic routes, account pages, nested pages, or single-page app views.

## How tab selection works

Median bottom tab bar items are selected automatically when a user taps a tab. The selected tab displays using the active tab color configured for your app.

For advanced navigation flows, you can control the selected tab in two ways:

| Method | Best for |
| - | - |
| JavaScript Bridge | Selecting or deselecting tabs from your website code |
| URL rules | Automatically selecting a tab when the current page URL matches a pattern |

## Implementation guide

### Select tab via JavaScript Bridge

Use the Median JavaScript Bridge to select a bottom tab bar item from your website code.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.tabNavigation.selectTab(1);
```

> [!NOTE]
>
> Tabs are 0-indexed, so `median.tabNavigation.selectTab(1)` selects the second tab.

#### Deselect all tabs

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.tabNavigation.deselect();
```

### Select tabs using URL rules

A given page that corresponds to a tab bar button may be opened through other means, for example a link on another page. In this case, you'll want to show that tab bar button as active when the page is displayed, even though there was no click event. To do this, specify a URL pattern in the `regex` field for each tab link defined in your JSON. The tab button is then active whenever a page matching the rule is displayed.

In the below example we show the "My Account" tab button as active whenever a page under `/account` is displayed within the app.

```json JSON theme={null}
{
  "tabSelectionConfig": [
    {
      "id": "1",
      "regex": ".*"
    }
  ],
  "tabMenus": [
    {
      "id": "1",
      "items": [
        {
          "subLinks": [],
          "label": "My Account",
          "icon": "fas fa-user",
          "url": "https://domain.com/account",
          "regex": "https://domain\\.com/account.*"
        }
      ]
    }
  ],
  "active": true
}
```

## Best practices

* Use JavaScript Bridge tab selection when your website controls the navigation state directly.
* Use URL rules when the active tab should be determined automatically from the current page URL.
* Use specific URL patterns for each tab to avoid conflicting active states.
* Test tab selection on both iOS and Android after updating your tab configuration.
* For single-page apps, update tab selection when the route changes if the app does not perform a full page load.


## Related topics

- [Dynamic tab menu](https://docs.median.co/docs/dynamic-tab-menu.md)
- [Bottom tab bar](https://docs.median.co/docs/bottom-tab-bar.md)
- [Localized tab menu](https://docs.median.co/docs/localized-tab-menu.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.