The CodeBlock component provides syntax highlighting powered by Shiki, with support for line numbers, code wrapping, line highlighting, focus mode, expandable content, and copy-to-clipboard functionality.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mintlify/components/llms.txt
Use this file to discover all available pages before exploring further.
Basic Usage
CodeBlock Props
The programming language for syntax highlighting (e.g., “javascript”, “python”, “java”). Supports all languages that Shiki supports.
Alias for
language prop.Display a filename in the code block header. When set, displays a header section with gray background.
Icon to display in the code block header (e.g., “js”, “python”, “java”). Requires
filename to be set to display the header.Enable line numbers on the left side of the code block.
Enable code wrapping instead of horizontal scrolling. Long lines will wrap to the next line.
Make the code block expandable/collapsible when content exceeds a certain height. Shows a “Show more/less” button at the bottom.
Lines to highlight as a JSON stringified array (e.g.,
"[1,3,4,5]"). Highlighted lines have a colored background.Lines to focus on (dims other lines) as a JSON stringified array (e.g.,
"[2,4,6]"). Non-focused lines are faded.The UI theme for the code block container (border, background, text color):
"system": Adapts to light/dark mode"dark": Always uses dark theme
Custom syntax highlighting theme. Can be:
- A string:
"system"or"dark"for default themes - An object with a
themeproperty for Shiki themes:- Single theme:
{ theme: "dracula" } - Dual themes:
{ theme: { light: "everforest-light", dark: "dracula" } }
- Single theme:
Use smaller text size (text-xs instead of text-sm).
Additional CSS classes for the code block container.
Props to customize the copy button behavior and appearance. See Copy Button Props below.
The code content to display.
Copy Button Props
Whether to show the tooltip on hover.
Aria label for the copy button for screen readers.
Text to display in the tooltip before copying.
Text to display in the tooltip after successful copy.
Callback function called after copy attempt. Receives the copy result (“success” or “error”) and the copied text.
Examples
With Filename and Icon
With Line Numbers
With Line Highlighting
Highlight specific lines to draw attention to important code:With Focus Mode
Focus on specific lines while dimming others:Highlight and Focus Combined
With Code Wrapping
Expandable Code Block
For long code snippets, enable expandable mode:Custom Shiki Theme
Use any Shiki theme for syntax highlighting:Dual Themes (Light/Dark)
Provide different themes for light and dark modes:Language Support
CodeBlock supports syntax highlighting for hundreds of programming languages through Shiki, including: Popular Languages:- JavaScript, TypeScript, JSX, TSX
- Python, Java, C++, C#, Go, Rust
- Ruby, PHP, Swift, Kotlin, Scala
- HTML, CSS, SCSS, LESS
- SQL, GraphQL, JSON, YAML, TOML, XML
- Bash, Shell, PowerShell, Zsh
- Dockerfile, Docker Compose
- Nginx, Apache
- .env files, INI files
- React, Vue, Svelte, Angular
- Markdown, MDX
- Prisma, Protocol Buffers
- Regular Expressions (regex)
Available Shiki Themes
The component supports all standard Shiki themes including:andromeeda,aurora-x,ayu-darkcatppuccin-frappe,catppuccin-latte,catppuccin-macchiato,catppuccin-mochadark-plus,dracula,dracula-softeverforest-dark,everforest-lightgithub-dark,github-dark-default,github-dark-dimmed,github-dark-high-contrastgithub-light,github-light-default,github-light-high-contrastgruvbox-dark-hard,gruvbox-dark-medium,gruvbox-dark-softgruvbox-light-hard,gruvbox-light-medium,gruvbox-light-softhouston,kanagawa-dragon,kanagawa-lotus,kanagawa-wavelaserwave,light-plus,material-theme,material-theme-darkermaterial-theme-lighter,material-theme-ocean,material-theme-palenightmin-dark,min-light,monokai,night-owl,nordone-dark-pro,one-light,plastic,poimandresred,rose-pine,rose-pine-dawn,rose-pine-moonslack-dark,slack-ochin,snazzy-lightsolarized-dark,solarized-light,synthwave-84tokyo-night,vesper,vitesse-black,vitesse-dark,vitesse-lightcss-variables
Copy to Clipboard
The CodeBlock automatically includes a copy-to-clipboard button that:- Appears in the top-right corner
- Shows a tooltip on hover (“Copy” / “Copied!”)
- Hides if the clipboard API is unavailable
- Can be customized via
copyButtonProps
Customizing Copy Button
Advanced Examples
All Features Combined
Responsive Code Blocks
Adjust text size for mobile devices:Accessibility
- The copy button includes proper
aria-labelattributes - Code blocks use semantic HTML with proper
langattributes - Keyboard navigation is fully supported
- Focus indicators are visible and clear
BaseCodeBlock
TheBaseCodeBlock component is a lower-level component that CodeBlock is built on. It provides the core syntax highlighting functionality without the header and copy button.
BaseCodeBlock Props
AllCodeBlock props plus:
Internal prop used when rendered inside a CodeGroup. Adjusts height and overflow behavior.
Whether to apply syntax highlighting. Set to
false to skip highlighting for performance.Force extraction of code string from children in specific scenarios.
Usage
CodeBlock instead, which includes the copy button and header functionality.
Diff Syntax Support
CodeBlocks support diff syntax for showing code changes:- will be highlighted as removed (red), and lines starting with + will be highlighted as added (green).
Notes
- The component uses Shiki for syntax highlighting, providing accurate, language-aware highlighting
- Line highlighting and focus can be combined for powerful code demonstrations
- The expandable feature automatically calculates height based on content
- When using
filenameoricon, the code block displays a header section - The fade overlay (gradient edge effect) is disabled when using
wrap,highlight,focus, orexpandable - Copy button automatically hides if the browser doesn’t support the Clipboard API (non-HTTPS contexts)
- Syntax highlighting is powered by Shiki, the same highlighter used by VS Code
- The component supports both light and dark themes with automatic theme switching