# Tabs

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/tabs
- **Markdown:** https://refast.fastapicloud.dev/docs/components/tabs.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/data_display/tabs.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Tab panels for switching between related views. Each `TabItem` bundles
the trigger button and its content panel into a single component.

```python
from refast.components import Tabs, TabItem

Tabs(
    default_value="overview",
    children=[
        TabItem(
            value="overview",
            label="Overview",
            children=[Text("Overview content here.")],
        ),
        TabItem(
            value="settings",
            label="Settings",
            children=[Text("Settings content here.")],
        ),
    ],
)
```

Manage your account settings and profile information.

Change your password and configure two-factor authentication.

Configure how and when you receive notifications.

```python
# Uncontrolled — browser manages state
Tabs(
    default_value="tab-0",
    children=[
        TabItem(value="tab-0", label="Account", children=[...]),
        TabItem(value="tab-1", label="Password", children=[...]),
        TabItem(value="tab-2", label="Notifications", children=[...]),
    ],
)
```

## Tabs Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `children` | `list` | `[]` | `TabItem` components. |
| `default_value` | `str \| None` | `None` | Initially active tab value (uncontrolled). |
| `value` | `str \| None` | `None` | Controlled active tab value. |
| `on_value_change` | `Callback \| None` | `None` | Fired when the active tab changes. `ctx.event_data` is the new value string. |
| `direction` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction of the tabs. |
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"md"` | Size of the tab triggers. |
| `gap` | `int \| None` | `None` | Gap in pixels between tab buttons. |
| `tab_list_class_name` | `str` | `""` | Extra Tailwind classes for the tab buttons list container. |
| `tab_list_style` | `dict \| None` | `None` | Inline styles for the tab buttons list container. |
| `stretch` | `bool` | `False` | Whether triggers should stretch to fill the horizontal width (horizontal layout) or vertical list container width. |
| `class_name` | `str` | `""` | Extra Tailwind classes for the outer wrapper. |
| `style` | `dict \| None` | `None` | Inline styles for the outer wrapper. |

## TabItem Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `value` | `str` | *(required)* | Unique identifier within the `Tabs` group. |
| `label` | `str` | *(required)* | Text displayed on the tab trigger button. |
| `icon` | `str \| None` | `None` | Lucide icon name shown before the label. |
| `children` | `list` | `[]` | Panel content shown when this tab is active. |
| `disabled` | `bool` | `False` | Grays out and disables the tab trigger. |
| `class_name` | `str` | `""` | Extra Tailwind classes. |

## Setting the Width of Tabs

There are three main ways you might want to control the width when using tabs:
1. **The overall Tabs component width**: Customize this by setting `class_name` (e.g. `class_name="w-full"` or `class_name="w-[500px]"`) or using `style` (e.g. `style={"width": "500px"}`).
2. **The tab buttons sidebar (tab list) width (Vertical Layout)**: Customize this using `tab_list_class_name` (e.g. `tab_list_class_name="w-48"`) or `tab_list_style` (e.g. `tab_list_style={"width": "200px"}`).
3. **Stretching triggers to full width (Horizontal Layout)**: Set `stretch=True` to make the horizontal tab buttons list full width (`w-full flex`) and force the buttons to stretch equally to fill the space (`flex-1`).

## Uncontrolled (browser state)

```python
Tabs(
    default_value="tab1",
    children=[
        TabItem(value="tab1", label="Tab 1", children=[Text("Content 1")]),
        TabItem(value="tab2", label="Tab 2", children=[Text("Content 2")]),
    ],
)
```

## Controlled (Python state)

```python
async def set_tab(ctx: Context, value: str):
    ctx.state.set("active_tab", value)
    await ctx.refresh()

def render(ctx: Context):
    active = ctx.state.get("active_tab", "tab1")
    return Tabs(
        value=active,
        on_value_change=ctx.callback(set_tab),
        children=[
            TabItem(value="tab1", label="Tab 1", children=[Text("Content 1")]),
            TabItem(value="tab2", label="Tab 2", children=[Text("Content 2")]),
        ],
    )
```

## Tabs with icons

```python
Tabs(
    default_value="profile",
    children=[
        TabItem(value="profile", label="Profile", icon="user"),
        TabItem(value="settings", label="Settings", icon="settings"),
        TabItem(value="billing", label="Billing", icon="credit-card"),
    ],
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
