DocumentationNuxt Charts v3

Code Block

A syntax-highlighted code block with CSS-based themes and one-click copy.

Use CodeBlock to display syntax-highlighted code with optional line numbers and clipboard copying. It works in Vue or Nuxt with Tailwind CSS and inherits Nuxt UI colors when available. It uses Shiki directly, with no Nuxt module or application theme state required.

Example

Learn how to use the Nuxt Charts CLI to get premium components.

Props

PropTypeDefaultDescription
codestring—The source code to display.
languagestring'text'Language for syntax highlighting (e.g. vue, typescript, bash).
filenamestringundefinedFilename shown in the header. Falls back to language.
showLineNumbersbooleanfalseDisplay line numbers.
highlighter'shiki' | 'lowlight''shiki'Highlighting engine to use. Both engines work in Vue and Nuxt.
themestringundefinedExplicit Shiki theme. Overrides darkTheme / lightTheme.
darkThemestring'github-dark'Shiki theme used in dark color mode.
lightThemestring'github-light'Shiki theme used in light color mode.
maxHeightstring | numberundefinedMax height of the code area (e.g. 400 or '50vh'). Scrollable when exceeded.
loadingbooleanfalseShows the loading slot instead of code.
showHeaderbooleantrueShow the filename and copy button header.
showCopybooleantrueShow the copy button when the header is visible.
copyLabelstring'Copy code'Copy button text and accessible label.
copiedLabelstring'Copied!'Button text after a successful copy.
emptyLabelstring'No code provided'Empty state text.

Theme Support

By default the component automatically switches between github-light and github-dark using the ancestor .dark class. Override per-instance with theme, or set separate darkTheme / lightTheme props:

<template>
  <!-- Fixed theme -->
  <CodeBlock theme="nord" language="typescript" :code="tsCode" />

  <!-- Per color mode -->
  <CodeBlock dark-theme="one-dark-pro" light-theme="github-light" language="vue" :code="code" />
</template>

Requirements

Install the highlighting dependencies in your Vue or Nuxt project:

npm install shiki lowlight hast-util-to-html

Both engines are loaded on demand. Unsupported languages or themes fall back to escaped plain text and emit highlight-error.

Presentation and Events

showHeader and showCopy default to true. Set showHeader to false to display only the code. Customize button and empty-state text with copyLabel, copiedLabel, and emptyLabel.

The header slot receives filename and language; loading and empty slots replace those states. The component emits copy with the copied source, copy-error if clipboard access fails, and highlight-error if highlighting fails.

Dual Shiki themes follow the ancestor .dark class through CSS. An explicit theme keeps that theme in both modes. Lowlight uses semantic CSS colors. Clipboard copying requires a secure browser context.