Code Block
Displays syntax-highlighted code with essential developer experience features. Perfect for documentation, blogs, and technical content where code clarity matters.
Powered by Shiki for accurate syntax highlighting that matches VS Code themes, with built-in support for copy buttons, line numbers, and collapsible long code blocks.
Installation
shellUsage
tsxProps
Shiki Config
Preview Background Props
Examples
Basic Code Block
Display simple code with default settings:
tsxWith File Path
Show the file name above the code block:
tsxCustom Theme
Use custom Shiki themes for light and dark modes:
tsxMinimal Code Block
Hide optional UI elements for a cleaner look:
tsxWith Component Preview
Show a live preview above the code:
tsxPreview with Dots Background
Add visual interest to component previews:
tsxCollapsed Long Code
Long code blocks automatically collapse:
tsxLanguages
Code Block supports all languages supported by Shiki, including:
- JavaScript/TypeScript:
javascript,typescript,jsx,tsx - Web:
html,css,scss,sass,less - Backend:
python,java,php,ruby,go,rust - Shell:
bash,sh,zsh,fish,powershell - Data:
json,yaml,toml,xml - Databases:
sql,graphql - Config:
dockerfile,nginx,apache - And 200+ more languages
See Shiki's language list for the complete list.
Accessibility
Code Block provides comprehensive accessibility features:
Keyboard Navigation
- Tab - Navigate to copy button and expand/collapse button
- Enter/Space - Activate copy or expand/collapse
- Escape - Dismiss any focus states
Screen Readers
- Copy button announces action and success state
- Language badge announces code language
- Line numbers are hidden from screen readers to avoid noise
- Expand/collapse button announces current state
Copy Functionality
- Visual feedback on copy success (checkmark icon)
- Keyboard accessible copy button
- Works with screen reader users
Changelog
Added
- Syntax highlighting powered by Shiki
- Copy-to-clipboard functionality
- Line numbers display
- Language badge
- Collapsible long code blocks
- Component preview section
- Dotted and custom background patterns
- File path display
- Custom theme support
- Auto theme switching (light/dark)