Tabs Component

Tab component

Published December 10, 20251 min readUpdated September 9, 2026

Tabs Component

Tabs are a common UI pattern used to switch between related sections of content without navigating away from the page. They help organize information in a structured and compact layout while keeping the interface clean.

In this component, I first built a simple state-driven version and then evolved it into a reusable compound component using React context.


Basic Version

The initial implementation used local state to track the active tab.

This works well for small cases but becomes difficult to scale or customize.

The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser.

Compound Component Version

To make the component reusable and extensible, I broke it into smaller parts:

This enables a clean and declarative API:

<Tabs defaultValue="html">
  <TabsList>
    <TabsTrigger value="html">HTML</TabsTrigger>
    <TabsTrigger value="css">CSS</TabsTrigger>
  </TabsList>
 
  <TabsContent value="html">...</TabsContent>
  <TabsContent value="css">...</TabsContent>
</Tabs>

The HyperText Markup Language or HTML is the standard markup language for documents designed to be displayed in a web browser.