Tabs
Use these responsive tabs components to create a secondary navigational hierarchy for your website or toggle content inside a container
FullWidthTabs: View Source Code
InteractiveTabHead, TabContent: View Source Code
The tabs component can be used either as an extra navigational hierarchy complementing the main navbar or you can also use it to change content inside a container just below the tabs using the data attributes from Flowbite.
Setup
<script>
import { DefaultTabs, UnderlineTabs, IconTabs, PillTabs, FullWidthTabs, InteractiveTabs, InteractiveTabHead, TabContent } from 'flowbite-svelte';
</script>
Default tabs
Use the following default tabs component example to show a list of links that the user can navigate from on your website.
<script>
import { DefaultTabs } from "flowbite-svelte";
export let tabs = [
{
name: "Profile",
active: true,
href: "/#",
rel: undefined,
},
{
name: "Dashboard",
active: false,
href: "/#",
rel: undefined,
},
{
name: "Settings",
active: false,
href: "/#",
rel: undefined,
},
{
name: "Contacts",
active: false,
href: "/#",
rel: undefined,
},
];
</script>
<DefaultTabs {tabs} />
Tabs with underline
Use this alternative tabs component style with an underline instead of a background when hovering and being active on a certain page.
<script>
import { UnderlineTabs }from 'flowbite-svelte';
let tabs = [
{
name: "Profile",
active: true,
href: "/#",
rel: undefined,
},
{
name: "Dashboard",
active: false,
href: "/#",
rel: undefined,
},
{
name: "Settings",
active: false,
href: "/#",
rel: undefined,
},
{
name: "Contacts",
active: false,
href: "/#",
rel: undefined,
},
];
</script>
<UnderlineTabs {tabs} />
Tabs with icons
This is an example of the tabs component where you can also use a SVG powered icon to complement the text within the navigational tabs.
<script>
import { IconTabs } from 'flowbite-svelte';
import {
UserCircle,
ViewGrid,
Adjustments,
ClipboardList
} from 'svelte-heros';
let iconTabs = [
{
name: 'Profile',
active: true,
href: '/',
icon: UserCircle,
iconSize: 18,
},
{
name: 'Dashboard',
active: false,
href: '/',
icon: ViewGrid,
iconSize: 18,
},
{
name: 'Settings',
active: false,
href: '/',
icon: Adjustments,
iconSize: 18,
},
{
name: 'Contacts',
active: false,
href: '/',
icon: ClipboardList,
iconSize: 18,
}
];
</script>
<IconTabs tabs={iconTabs} />
Pills tabs
If you want to use pills as a style for the tabs component you can do so by using this example.
<script>
import { PillTabs } from "flowbite-svelte";
let pillsTabs = [
{
name: "Profile",
selected: true,
href: "/profile",
},
{
name: "Dashboard",
selected: false,
href: "/dashboard",
},
{
name: "Settings",
selected: false,
href: "/settings",
},
{
name: "Contact",
selected: false,
href: "/contact",
},
];
</script>
<PillTabs tabs={pillsTabs} />
Full width tabs
If you want to show the tabs on the full width relative to the parent element you can do so by using the full width tabs component example.
<script>
import { FullWidthTabs } from 'flowbite-svelte'
let tabLabel = 'Select a target'
let tabs = [
{
name: "Profile",
active: true,
href: "/#",
rel: undefined,
},
{
name: "Dashboard",
active: false,
href: "/",
},
{
name: "Settings",
active: false,
href: "/",
},
{
name: "Contacts",
active: false,
href: "/",
},
];
</script>
<FullWidthTabs {tabs} {tabLabel}/>
Interactive tabs
Use the dynamic tabs component to interactively show and hide the content below the tabs based on the currently active tab item.
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<script>
import { InteractiveTabs } from "flowbite-svelte";
let tabs1 = [
{
name: "Profile-1",
id: 1,
content:
"1-1 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Dashboard-1",
id: 2,
content:
"1-2 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Settings-1",
id: 3,
content:
"1-3 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Contacts-1",
id: 4,
content:
"1-4Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
];
</script>
<InteractiveTabs tabId="myTab1" tabs={tabs1} />
Interactive tabs 2
It is possible to add other components to the InteractiveTabs
component but using InteractiveTabHead
and TabContent
make it easy to add other components to tabs. Here we are adding a timeline component in the tab 1:
-
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
Learn more -
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
-
Lorem ipsum dolor sit amet
Consectetur adipiscing elit...
<script>
import { InteractiveTabHead, TabContent, Card, Timeline,
TimelineItem, }from 'flowbite-svelte';
let tab1 = { name: 'Tab1', id: 1 };
let tab2 = { name: 'Tab2', id: 2 };
let tab3 = { name: 'Tab3', id: 3 };
let tabhead = [tab1, tab2, tab3];
let timelineItems = [
{
date: 'February 2022',
title: 'Lorem ipsum dolor sit amet',
href: '/',
linkname: 'Learn more',
text: 'Consectetur adipiscing elit...'
},
{
date: 'March 2022',
title: 'Lorem ipsum dolor sit amet',
text: 'Consectetur adipiscing elit...'
},
{
date: 'February 2022',
title: 'Lorem ipsum dolor sit amet',
text: 'Consectetur adipiscing elit...'
}
];
</script>
<InteractiveTabHead tabs={tabhead}>
<TabContent tab={tab1}>
<Timeline>
<TimelineItem {timelineItems} />
</Timeline>
</TabContent>
<TabContent tab={tab2}>
<p>Test 2 content here</p>
</TabContent>
<TabContent tab={tab3}>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla distinctio.</p>
</TabContent>
</InteractiveTabHead>
Multiple Interactive Tabs
1-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
2-1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<script>
import { InteractiveTabs } from "flowbite-svelte";
let tabs1 = [
{
name: "Profile-1",
id: 1,
content:
"1-1 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Dashboard-1",
id: 2,
content:
"1-2 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Settings-1",
id: 3,
content:
"1-3 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Contacts-1",
id: 4,
content:
"1-4 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
];
let tabs2 = [
{
name: "Profile-2",
id: 1,
content:
"2-1 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Dashboard-2",
id: 2,
content:
"2-2 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Settings-2",
id: 3,
content:
"2-3 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
{
name: "Contacts-2",
id: 4,
content:
"2-4 Lorem ipsum dolor sit amet, consectetur adipiscing ... ",
},
];
</script>
<InteractiveTabs tabId="myTab1" tabs={tabs1} />
<InteractiveTabs tabId="myTab2" tabs={tabs2} />
Props
The component has the following props, type, and default values. See types page for type information.
DefaultTabs
Name | Type | Default |
---|---|---|
tabs | TabType[] |
UnderlineTabs
Name | Type | Default |
---|---|---|
divClass | string | 'text-sm font-medium text-center text-gray-500 border-b border-gray-200 dark:text-gray-400 dark:border-gray-700' |
tabs | TabType[] |
IconTabs
Name | Type | Default |
---|---|---|
tabs | IconTabType[] | |
iconClass | string | 'mr-2 w-5 h-5 text-gray-400 group-hover:text-gray-500 dark:text-gray-500 dark:group-hover:text-gray-300' |
PillTabs
Name | Type | Default |
---|---|---|
tabs | PillTabType[] |
FullWidthTabs
Name | Type | Default |
---|---|---|
tabs | TabType[] | |
tabLabel | string |
InteractiveTabs
Name | Type | Default |
---|---|---|
tabId | string | 'myTab' |
activeTabValue | number | 1 |
tabs | InteractiveTabType[] |
InteractiveTabHead
Name | Type | Default |
---|---|---|
tabs | TabHeadType[] | |
tabId | string | 'myTab' |
activeTabValue | number | 1 |
TabContent
Name | Type | Default |
---|---|---|
divClass | string | 'p-4 rounded-lg dark:bg-gray-800' |
tab | TabHeadType |