# Tabs

> A Layout widget for organizing content into separate views accessible via a navigation bar

Tabs widgets are [Layout Fields](https://golemui.com/dx/widgets-reference/layout-fields/overview.md) that allow users to switch between different content areas within the same context. They are highly effective for breaking down large forms into logical, manageable pieces.


```ts title="tabs.ts"

export default [
  gui.layouts.tabs([
    {
      label: 'Personal',
      uid: 'tab_personal',
      children: [
        gui.inputs.textInput('personal_email', {
          label: 'Personal Email',
        }),
      ],
    },
    {
      label: 'Work',
      uid: 'tab_work',
      children: [
        gui.inputs.textInput('work_email', {
          label: 'Work Email',
        }),
      ],
    },
    {
      label: 'Other',
      uid: 'tab_other',
      children: [
        gui.inputs.textarea('notes', {
          label: 'Additional Notes',
        }),
      ],
    },
  ], {
    defaultOpen: 'tab_personal',
    uid: 'tabs_basic',
  }),
];
```

_Live demo on the docs page. Form definition: [tabs.ts](https://golemui.com/template/widgets-dx/tabs/tabs.ts)._

## Props

Use these `props` to customize your Tabs widget.

| prop          | type   | description                                                                                                                                                                                     |
| ------------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `tabs`        | array  | **Required**. Array of tab definitions: `{ label, uid }`. The `label` is a string or a translation config `{ key, params?, default? }`. Each `uid` must match the `uid` of one of the children. |
| `defaultOpen` | string | The `uid` of the tab that should be active on initial render. Defaults to the first tab                                                                                                         |
| `renderMode`  | string | `'all'` keeps every tab panel mounted in the DOM and toggles visibility; `'activeOnly'` mounts the active tab's children only while it is open. Defaults to `'all'`                             |

### Default Open

Use `defaultOpen` to select which tab is active on first render. Set it to the `uid` of any tab — here, the second tab is selected on load.


```ts title="tabs.ts"

export default [
  gui.layouts.tabs([
    {
      label: 'Personal',
      uid: 'tab_personal',
      children: [
        gui.inputs.textInput('personal_email', {
          label: 'Personal Email',
        }),
      ],
    },
    {
      label: 'Work',
      uid: 'tab_work',
      children: [
        gui.inputs.textInput('work_email', {
          label: 'Work Email',
        }),
      ],
    },
    {
      label: 'Other',
      uid: 'tab_other',
      children: [
        gui.inputs.textarea('notes', {
          label: 'Additional Notes',
        }),
      ],
    },
  ], {
    defaultOpen: 'tab_work',
    uid: 'tabs_default_open',
  }),
];
```

_Live demo on the docs page. Form definition: [tabs-default-open.ts](https://golemui.com/template/widgets-dx/tabs/tabs-default-open.ts)._

### Render Mode

Use `renderMode` to control when tab children are mounted. The default `'all'` keeps every panel in the DOM and hides inactive ones, which preserves child state and form values as the user switches tabs. Use `'activeOnly'` to mount a tab's children only while it is active — useful when panels contain expensive widgets, side effects on mount, or media you don't want loaded up front. Inspect the rendered DOM as you switch tabs to see the difference.


```ts title="tabs.ts"

export default [
  gui.layouts.tabs([
    {
      label: 'Personal',
      uid: 'tab_personal',
      children: [
        gui.inputs.textInput('personal_email', {
          label: 'Personal Email',
        }),
      ],
    },
    {
      label: 'Work',
      uid: 'tab_work',
      children: [
        gui.inputs.textInput('work_email', {
          label: 'Work Email',
        }),
      ],
    },
    {
      label: 'Other',
      uid: 'tab_other',
      children: [
        gui.inputs.textarea('notes', {
          label: 'Additional Notes',
        }),
      ],
    },
  ], {
    defaultOpen: 'tab_personal',
    renderMode: 'activeOnly',
    uid: 'tabs_render_mode',
  }),
];
```

_Live demo on the docs page. Form definition: [tabs-render-mode.ts](https://golemui.com/template/widgets-dx/tabs/tabs-render-mode.ts)._

## Accessibility

The widget renders the full `tablist` / `tab` / `tabpanel` role pattern, and each panel is focusable: after activating a tab, one more <kbd>Tab</kbd> keypress moves focus into the panel, so keyboard users land on the revealed content instead of skipping past it.

## Styling

Tabs can be styled as explained in the [Styling Guide](https://golemui.com/dx/styling/overview.md).

### CSS Variables

Following you will find a list with the CSS Variables used to style the tabs.

| CSS Variable           | Description                                 |
| ---------------------- | ------------------------------------------- |
| `--gui-bg-default`     | Background color for tab buttons and panels |
| `--gui-border-default` | Border color for tab buttons and panels     |
| `--gui-text-default`   | Text color for labels                       |
| `--gui-space-3`        | Padding inside tab buttons and panels       |
| `--gui-radius-md`      | Border radius for tab buttons and panels    |

### Anatomy

This is the anatomy of the Tabs Widget in case you want to use your CSS styles.


```html title="tabs-anatomy.html"
<gui-tabs-layout class="gui-tabs gui-field">
  <gui-tabs id="tabs_uid">
    <gui-tab-list role="tablist">
      <gui-tab
        panel="tab_personal"
        id="tab_tabs_uid_tab_personal"
        aria-selected="true"
        aria-controls="tabpanel_tabs_uid_tab_personal"
        tabindex="0"
        role="tab"
      >
        Personal
      </gui-tab>
      <gui-tab
        panel="tab_work"
        id="tab_tabs_uid_tab_work"
        aria-selected="false"
        aria-controls="tabpanel_tabs_uid_tab_work"
        tabindex="-1"
        role="tab"
      >
        Work
      </gui-tab>
      <gui-tab
        panel="tab_other"
        id="tab_tabs_uid_tab_other"
        aria-selected="false"
        aria-controls="tabpanel_tabs_uid_tab_other"
        tabindex="-1"
        role="tab"
      >
        Other
      </gui-tab>
    </gui-tab-list>
    <gui-tab-panel
      name="tab_personal"
      id="tabpanel_tabs_uid_tab_personal"
      aria-labelledby="tab_tabs_uid_tab_personal"
      role="tabpanel"
      tabindex="0"
    >
      <!-- Child widget: Personal Email -->
    </gui-tab-panel>
    <gui-tab-panel
      name="tab_work"
      id="tabpanel_tabs_uid_tab_work"
      hidden=""
      aria-labelledby="tab_tabs_uid_tab_work"
      role="tabpanel"
      tabindex="0"
    >
      <!-- Child widget: Work Email -->
    </gui-tab-panel>
    <gui-tab-panel
      name="tab_other"
      id="tabpanel_tabs_uid_tab_other"
      hidden=""
      aria-labelledby="tab_tabs_uid_tab_other"
      role="tabpanel"
      tabindex="0"
    >
      <!-- Child widget: Additional Notes -->
    </gui-tab-panel>
  </gui-tabs>
</gui-tabs-layout>
```
