Join our Discord community
Code

Code Tabs

Tabbed code display with syntax highlighting and copy functionality. Perfect for React applications requiring multi-variant code examples with Next.js integration and TypeScript support.

Powered by

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
npx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
bunx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json

Features

  • Multi-tab code display with smooth transitions between different code variants
  • Syntax highlighting using Shiki for accurate language-specific highlighting
  • Copy functionality with built-in copy button for each code snippet
  • TypeScript support with complete type definitions and IntelliSense
  • Theme-aware highlighting automatically adapts to light/dark themes using next-themes
  • Customizable languages supporting all Shiki language definitions

Examples

Package Manager Commands

Loading component...

Display installation commands for different package managers with automatic syntax highlighting.

Without Copy Button

Loading component...

Show code comparisons across frameworks without the copy functionality.

Use Cases

This free open source React component works well for:

  • Documentation sites - Display code examples for multiple platforms or languages built with Next.js
  • API documentation - Show request examples in different programming languages using TypeScript and Tailwind CSS
  • Tutorial content - Present alternative implementations or framework-specific code
  • Configuration examples - Display setup instructions for various environments with shadcn/ui integration

API Reference

CodeTabs

PropTypeDefaultDescription
codesRecord<string, string>requiredObject with tab names as keys and code content as values
langstring"bash"Language for syntax highlighting
themes{ light: string; dark: string }{ light: 'github-light', dark: 'github-dark' }Shiki themes for light and dark modes
copyButtonbooleantrueWhether to show the copy button
onCopy(content: string) => void-Callback when code is copied
defaultValuestringFirst key in codesInitially selected tab
valuestring-Controlled selected tab value
onValueChange(value: string) => void-Callback when tab selection changes

Supported Languages

The component supports all languages available in Shiki, including:

  • javascript, typescript, jsx, tsx - JavaScript ecosystem
  • python, ruby, go, rust - Popular languages
  • bash, shell, powershell - Shell scripting
  • json, yaml, toml - Configuration formats
  • html, css, scss - Web technologies
  • And many more...

Implementation Notes

  • Requires next-themes for theme detection
  • Code highlighting is performed asynchronously on mount
  • The component gracefully falls back to plain text if highlighting fails
  • Tab selection can be controlled or uncontrolled
  • Copy button uses the shadcn/ui CopyButton component