---
title: "Code block"
description: "Code blocks and code tabs for Shiki output."
url: https://docscn.dev/docs/components/codeblock
lastModified: 2026-10-28T02:05:06.000Z
---

# Code block (/docs/components/codeblock)

> Code blocks and code tabs for Shiki output.

## Installation [#installation]

```npm
npx shadcn@latest add @docscn/codeblock
```

## Usage [#usage]

`defaultMdxComponents` renders every code block in your MDX with `CodeBlock`. Fumadocs MDX's syntax works as usual:

````mdx
```ts title="greet.ts"
export function greet(name: string) {
  return `Hello, ${name}!`; // [\!code highlight]
}
```
````

```ts title="greet.ts"
export function greet(name: string) {
  return `Hello, ${name}!`; // [!code highlight]
}
```

- `title="..."` adds a title bar, with an icon for the language.
- The copy button copies the code.
- Shiki's notations add highlighted (`[!code highlight]`), added and removed (`[!code ++]`, `[!code --]`), focused (`[!code focus]`) and highlighted-word (`[!code word:x]`) styles, and `lineNumbers` shows line numbers.

Code blocks with `tab="..."` and ` ```npm ` blocks become code tabs, on shadcn/ui `tabs`:

```npm
npm install next-themes
```

## Props [#props]

<TypeTable
  type={{
    title: {
      description: <>The title bar's text.</>,
      type: "ReactNode",
    },
    icon: {
      description: (
        <>The title bar's icon. A string is treated as SVG markup.</>
      ),
      type: "ReactNode",
    },
    allowCopy: {
      description: <>Show the copy button.</>,
      type: "boolean",
      default: "true",
    },
    keepBackground: {
      description: <>Keep the background colour of the Shiki theme.</>,
      type: "boolean",
    },
    viewportProps: {
      description: <>Props for the scrolling area.</>,
      type: "HTMLAttributes",
    },
    Actions: {
      description: <>Replace the area that holds the copy button.</>,
      type: "(props) => ReactNode",
    },
  }}
/>

`CodeBlockTabs` also accepts `groupId` and `persist`, to keep the same tab selected across code tabs and page loads.

The component's CSS (the light and dark Shiki themes and the notation styles) was added to your global stylesheet. Add `not-docs-codeblock` to an element to opt it out.