Tabs

Tabs make it easy to explore and switch between different views.
Importimport{ Tabs }from"antd";

When To Use

Ant Design has 3 types of Tabs for different situations.

  • Card Tabs: for managing too many closeable views.
  • Normal Tabs: for functional aspects of a page.
  • Radio.Button: for secondary tabs.

Examples

Content of Tab Pane 1

Default activate first tab.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Tab 1

Disabled a tab.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Centered tabs.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Tab 2

The Tab with Icon.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Set indicator prop to custom indicator size and align.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of tab 1

In order to fit in more tabs, they can slide left and right (or up and down).

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of tab 1



You can also specify its direction or both side


Content of tab 1

You can add extra actions to the right or left or even both side of Tabs.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of tab 1
Content of card tab 1
Content of editable tab 1

Large size tabs are usually used in page header, and small size could be used in Modal.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Tab position:
Content of Tab 1

Tab's position: left, right, top or bottom. Will auto switch to top in mobile.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Another type of Tabs, which doesn't support vertical mode.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab 1

Only card type Tabs support adding & closable. +Use closable={false} to disable close.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Hide default plus icon, and bind event for customized trigger.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Use react-sticky-box and renderTabBar.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Content of Tab Pane 1

Use dnd-kit to make tabs draggable.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code

API

Common props ref:Common props

Tabs

PropertyDescriptionTypeDefaultVersion
activeKeyCurrent TabPane's keystring-
addIconCustomize add icon, only works with type="editable-card"ReactNode<PlusOutlined />4.4.0
animatedWhether to change tabs with animation.boolean | { inkBar: boolean, tabPane: boolean }{ inkBar: true, tabPane: false }
centeredCenters tabsbooleanfalse4.4.0
defaultActiveKeyInitial active TabPane's key, if activeKey is not setstringThe key of first tab
hideAddHide plus icon or not. Only works while type="editable-card"booleanfalse
indicatorCustomize size and align of indicator{ size?: number | (origin: number) => number; align: start | center | end; }-5.13.0
itemsConfigure tab contentTabItemType[]4.23.0
moreCustomize the collapse menuMoreProps{ icon: <EllipsisOutlined /> , trigger: 'hover' }
removeIconThe custom icon of remove, only works with type="editable-card"ReactNode<CloseOutlined />5.15.0
popupClassNameclassName for more dropdown.string-4.21.0
renderTabBarReplace the TabBar(props: DefaultTabBarProps, DefaultTabBar: React.ComponentClass) => React.ReactElement-
sizePreset tab bar sizelarge | middle | smallmiddle
tabBarExtraContentExtra content in tab barReactNode | {left?: ReactNode, right?: ReactNode}-object: 4.6.0
tabBarGutterThe gap between tabsnumber-
tabBarStyleTab bar style objectCSSProperties-
tabPositionPosition of tabstop | right | bottom | lefttop
destroyInactiveTabPaneWhether destroy inactive TabPane when change tabbooleanfalse
typeBasic style of tabsline | card | editable-cardline
onChangeCallback executed when active tab is changed(activeKey: string) => void-
onEditCallback executed when tab is added or removed. Only works while type="editable-card"(action === 'add' ? event : targetKey, action) => void-
onTabClickCallback executed when tab is clicked(key: string, event: MouseEvent) => void-
onTabScrollTrigger when tab scroll({ direction: left | right | top | bottom }) => void-4.3.0

More option at rc-tabs tabs

TabItemType

PropertyDescriptionTypeDefaultVersion
closeIconCustomize close icon in TabPane's head. Only works while type="editable-card". 5.7.0: close button will be hidden when setting to null or falseReactNode-
destroyInactiveTabPaneWhether destroy inactive TabPane when change tabbooleanfalse5.11.0
disabledSet TabPane disabledbooleanfalse
forceRenderForced render of content in tabs, not lazy render after clicking on tabsbooleanfalse
keyTabPane's keystring-
labelTabPane's head display textReactNode-
iconTabPane's head display iconReactNode-5.12.0
childrenTabPane's head display contentReactNode-
closableWhether a close (x) button is visible, Only works while type="editable-card"booleantrue

MoreProps

PropertyDescriptionTypeDefaultVersion
iconThe custom iconReactNode-
DropdownProps

Design Token

Component TokenHow to use?

Token NameDescriptionTypeDefault Value
cardBgBackground color of card tabstringrgba(0,0,0,0.02)
cardGutterGutter of card tabnumber2
cardHeightHeight of card tabstring | number40
cardPaddingPadding of card tabstring8px 16px
cardPaddingLGPadding of large card tabstring8px 16px 6px
cardPaddingSMPadding of small card tabstring6px 16px
horizontalItemGutterHorizontal gutter of horizontal tabnumber32
horizontalItemMarginHorizontal margin of horizontal tab itemstring
horizontalItemMarginRTLHorizontal margin of horizontal tab item (RTL)string
horizontalItemPaddingHorizontal padding of horizontal tab itemstring12px 0
horizontalItemPaddingLGHorizontal padding of large horizontal tab itemstring16px 0
horizontalItemPaddingSMHorizontal padding of small horizontal tab itemstring8px 0
horizontalMarginHorizontal margin of horizontal tabstring0 0 16px 0
inkBarColorColor of indicatorstring#1677ff
itemActiveColorText color of active tabstring#0958d9
itemColorText color of tabstringrgba(0,0,0,0.88)
itemHoverColorText color of hover tabstring#4096ff
itemSelectedColorText color of selected tabstring#1677ff
titleFontSizeFont size of titlenumber14
titleFontSizeLGFont size of large titlenumber16
titleFontSizeSMFont size of small titlenumber14
verticalItemMarginVertical margin of vertical tab itemstring16px 0 0 0
verticalItemPaddingVertical padding of vertical tab itemstring8px 24px
zIndexPopupz-index of dropdown menunumber1050

Global TokenHow to use?