Powerful and customizable React code snippet components built for modern applications and websites. These code snippets are built using Shiki and styled with Tailwind CSS.
Installation
You can add this code snippet component using our CLI or manually:
npx untitledui@latest add code-snippet
Code snippet examples
Below are examples and variations of this code snippet component:
API reference
Import the parts and assemble them:
import { CodeSnippet } from "@/components/application/code-snippet/code-snippet"; <CodeSnippet.Tabs> <CodeSnippet.TabList> <CodeSnippet.Tab /> </CodeSnippet.TabList> <CodeSnippet.TabPanel> <CodeSnippet /> </CodeSnippet.TabPanel> </CodeSnippet.Tabs>
CodeSnippet
Also accepts all standard HTML attributes, all aria-* attributes, all standard React DOM event handlers.
CodeSnippet.Tab
Renders React Aria’s Tab — all of its props are supported.
Props from React Aria (29)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
CodeSnippet.TabList
Renders a <div> element.
Styling (3)
Accessibility (4)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
CodeSnippet.TabPanel
Renders React Aria’s TabPanel — all of its props are supported.
Styling (4)
Accessibility (4)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
CodeSnippet.Tabs
Renders React Aria’s Tabs — all of its props are supported.
Styling (5)
Accessibility (4)
Also accepts the global HTML attributes (dir, lang, hidden, inert, translate), all standard React DOM event handlers.
FAQs
Please refer to our frequently asked questions page for more.
Pass your source as the code string together with the required language prop, and the component highlights it on the client with Shiki's codeToHast and renders the result with hast-util-to-jsx-runtime, so both packages need to be installed. To pass pre-highlighted output instead, generate it with the exported highlight(code, language) helper and pass it as children.
Set showLineNumbers={false}. It defaults to true. The prop controls the line-number gutter only: turning it off replaces the gutter with uniform padding around the code. The wrapper styling is separate — the modern prop (default true) is what decides between the shadowed wrapper and a plain bordered block.
Give the snippet a maxHeight in pixels, for example maxHeight={320}. The component measures the content and only renders the gradient overlay and the Show more / Show less toggle when the code actually exceeds that height; omit maxHeight and the block always renders at full height.
Any language in Shiki's web bundle can be passed to language. The type includes convenience literals for "tsx", "ts", "typescript", "jsx", "js", "javascript", "json", "html", "css" and "bash", plus Shiki's special languages such as "text".
Use the compound tab parts: CodeSnippet.Tabs wraps CodeSnippet.TabList with a CodeSnippet.Tab per file, and one CodeSnippet.TabPanel per file containing a CodeSnippet. They are built on React Aria Tabs with keyboardActivation="manual", so arrow keys move between tabs and Enter or Space activates one.
A copy button renders whenever a code string is set and appears on hover or keyboard focus, so a snippet that only receives children has no copy button. Inside CodeSnippet.Tabs, the tab list adds its own copy button that copies the active panel's text. For an expand action, pass an onExpand callback; that button only renders when the prop is provided.
Yes. It highlights with the github-light and github-dark themes and remaps several token colors onto design tokens such as --color-text-primary and --color-utility-blue-600. The bundled code-snippet.style.css switches to the dark colors when an ancestor has the dark-mode class.