navigations
Tailwind CSS Tabs & Pills
Tabs allow users to easily switch between different views, providing a seamless and efficient navigation experience.
Utilize the tab JavaScript plugin to improve our navigation tabs and pills, allowing us to create tabbed sections with different content.
For dynamic tabbed interfaces, it’s important to include specific elements like role="tablist"
, role="tab"
, role="tabpanel"
, and other attributes as outlined in the WAI ARIA Authoring Practices. These help convey the structure and functionality to users who rely on assistive technologies like screen readers. As a good practice, use button
elements for the tabs instead of links to ensure they trigger changes without navigating to new pages.
Basic example of tab.
Style:
The tabs
class serves as the base component for tabbed interfaces, where adding the tabs-bordered
class gives the tab buttons an underlined appearance. The tab
class is applied to individual tab buttons, and using the active
class marks a tab as the initial active tab. The active-tab:{tw-utility-class}
modifier allows Tailwind utility classes to be applied when the tab is active.
Functionality:
The data-tab
data attribute is used to link each tab button to its corresponding tabpanel
using an ID. It’s crucial to set the role
attribute on both the tab
and tabpanel
elements to ensure proper functionality and accessibility.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Example with Filled tabs.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
To create vertical tabs, you can use the tabs-vertical
class. Additionally, you should add a flex
class to a surrounding div
to ensure the tabs and their associated content are displayed side by side.
For keyboard accessibility to function properly, please set data-attribute data-tabs-vertical
to true
.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
The following example demonstrates a extra small tab using the tabs-xs
class.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
The following example demonstrates a small tab using the tabs-sm
class.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
The following example demonstrates a default tab.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
The following example demonstrates a large tab using the tabs-lg
class.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Centered with TailwindCSS class justify-center
.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Align at the end TailwindCSS class justify-end
.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Below example shows tabs with icons.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Below example shows tabs with badges.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Apply the tabs-lifted
component class along with tabs
to display the tab in a lifted style.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
When content extends beyond the screen, a horizontal scrollbar ensures the tab bar remains aligned. Apply the horizontal-scrollbar
class for a custom scrollbar style. Resize the window to see an example.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Settings: Adjust your preferences, manage your account, and configure your privacy settings here.
Help: Find answers to frequently asked questions, get in touch with support, or read through user guides.
Notifications: Manage your notifications, set preferences, and view your notification history.
Feedback: Share your thoughts, report issues, or suggest new features to improve the platform.
The demonstration illustrates responsiveness by showcasing how the tabs switch to a select menu on smaller screens.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Below example shows tabs as segments.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Use component classes btn
and btn-text
to style pills with a button-like appearance.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Below example shows pills with icons.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Below example shows Filled pills.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
For tabs styled with the tabs-vertical
class and pills styled with Tailwind classes, please make sure they are distinct and not linked.
For keyboard accessibility to function properly, please set data-attribute data-tabs-vertical
to true
.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
The HSTabs
object is contained within the global window
object.
Below is a demonstration illustrating how to use the public methods. It might seem a bit complex because the open()
method requires the ID of the button with role="tab"
and data-tab="tabpanel-id"
, rather than just the tabpanel-id
.
In the example below, we’ve provided the ID tabs-method-3
and added an event listener to the openBtn
.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.
Open item (static method).
Below, is the demonstration on how to use the event. Apply the ID to the role=tablist
component class. To test these event, copy the following event into your console and click the button.
Welcome to the Home tab! Explore the latest updates and news here.
This is your Profile tab, where you can update your personal information and manage your account details.
Messages: View your recent messages, chat with friends, and manage your conversations.