Tailwind CSS Tabs Collection

Explore various tab styles crafted with Tailwind CSS. These components provide flexible navigation for organizing content within your web applications.

Each example includes a live preview and readily available HTML code. Simply copy the code snippet and integrate it into your Tailwind project. Remember to adapt the content and potentially add JavaScript for full interactive functionality if needed.

Standard Horizontal Tabs

Content for Profile tab.
Content for Settings tab.
Content for Notifications tab.

Vertical Tabs

Content for My Account tab.
Content for Company tab.
Content for Billing tab.

Icon + Text Tabs

Content for Account tab.
Content for Company tab.
Content for Projects tab.

Icon-Only Tabs

Content for Account tab.
Content for Settings tab.
Content for Notifications tab.

Underline Tabs

Content for Overview tab.
Content for Features tab.
Content for Details tab.

Pill-Style Tabs

Content for Active Pill tab.
Content for Inactive Pill tab.
Content for Another Pill tab.

Boxed Tabs

Content for Tab 1.
Content for Tab 2.
Content for Tab 3.

Scrollable Tabs (Horizontal Overflow)

Content for Tab Item 1.
Content for Tab Item 2.

Note: Requires the tailwind-scrollbar plugin (or similar) for styled scrollbars (scrollbar-thin etc.). Basic overflow works without it.

FAQ on Tailwind CSS Tabs

How do I create basic tabs using Tailwind CSS?

To create a tab navigation component, start with HTML markup using either <nav> with anchors or a <ul> with list items. Apply Tailwind utility classes like flex flex-wrap for horizontal layout. Add JavaScript for tab content switching functionality. Most UI component libraries like Flowbite and Material Tailwind offer ready-to-use implementations with proper ARIA tab roles for accessibility.

What's the proper way to handle tab accessibility?

Accessibility requires proper ARIA attributes when building tab panels. Use role="tablist" on the container, role="tab" for selectors, and role="tabpanel" for content sections. Include aria-selected, aria-controls, and aria-labelledby attributes to support screen readers. WAI-ARIA guidelines recommend using <button> elements for tabs since they trigger dynamic content changes rather than navigation.

Can I create vertical tabs with Tailwind?

Yes! While the standard tab layout is horizontal, creating vertical tabs arrangement is simple. Use Tailwind's flex direction utilities by changing flex-row to flex-col on your container. This creates a sidebar-style secondary navigation that works well in dashboards. Libraries like TW Elements and DaisyUI offer vertical tab variants with responsive behavior for different screen sizes.

How do I style the active tab state?

Style the active state using conditional classes. Apply distinctive styling for the active tab with classes like border-b-2 border-blue-500 for an underline effect or bg-blue-500 text-white for filled styling. Modern tab JavaScript plugins use data attributes to toggle classes. Active indicators are crucial for showing users their current location in the interface.

How do I toggle tab content visibility?

Control content visibility with JavaScript. Add click event listeners to tabs that hide all content sections and show only the targeted panel. Many frameworks like Alpine.js simplify this with declarative syntax. Libraries such as Preline UI provide complete solutions with smooth transition effects between tabs, handling all the DOM manipulation for you.

Do I need JavaScript for Tailwind tabs?

Yes, functional tabs require JavaScript for tab toggle behavior and event handling. While you can create the visual appearance with just Tailwind CSS, the interactive functionality needs JS. Options include writing custom JavaScript, using a library like Flowbite or Pagedone, or frameworks like React components that handle the logic internally through state management.

How can I add icons to my tabs?

Enhance user experience by incorporating SVG icons alongside text in tabs. Most component libraries support this pattern. Place SVG elements before text in your tab markup and style with Tailwind's spacing utilities. This creates a more intuitive UI design pattern and improves visual hierarchy. Many libraries offer premade components with icon support.

How do I make tabs responsive?

Build responsive tab interfaces by using Tailwind's breakpoint prefixes. For smaller screens, consider switching from horizontal to vertical layout, or implement a scrollable tab bar. Use overflow-x-auto for horizontal scrolling tabs. Some implementations use dropdown menus on mobile. Test thoroughly across devices to ensure proper content organization at all screen sizes.

What are pill-style tabs and how do I create them?

Pill-style tabs feature rounded corners and often use filled backgrounds instead of underlines. Create them by adding rounded-full or rounded-lg classes to your tabs. Add padding and adjust spacing for comfort. This style works well for content toggling in forms and settings pages. Libraries like Material Tailwind offer pre-built pill tab variants.

How do tabs differ from other navigation components?

Tabs serve as secondary navigation within a primary context, unlike main navigation bars. They organize related content in a single view without page reload, improving user interaction. Tabs typically control content directly below them, while navbars navigate between pages. Choose tabs when content belongs to the same context but needs categorical organization for better frontend development experiences.