WebberUI

Code Block

A syntax-highlighted code block with a copy button, a built-in lightweight tokenizer, and a line-by-line reveal animation.

A zero-dependency syntax-highlighted code block: it ships its own regex tokenizer (no shiki or prism required) and supports a filename header bar, line numbers, highlighting specific lines, one-click copy, and a line-by-line staggered fade in.

Loading preview…
npx shadcn@latest add https://webberui.com/r/code-block.json

Playground

Tune the props live — the code snippet updates as you go, so you can dial in the look you want before copying it.

<CodeBlock />

Installation

npx shadcn@latest add https://webberui.com/r/code-block.json

Or, once registries are configured in components.json, install it as @webberui/code-block.

Usage

import { CodeBlock } from "@/components/ui/code-block";

<CodeBlock
  code={`const hello = "world";`}
  language="tsx"
  filename="example.tsx"
  showLineNumbers
/>

Supported language keywords: tsx, jsx, ts, js, python, bash, css, json, html. An unknown language falls back to a generic mode that still highlights strings, comments, and numbers.

Props

PropTypeDefaultDescription
codestringThe code string to display
languagestring"tsx"Language tag, which decides the keyword and comment syntax
filenamestringFilename/title shown on the left of the header bar
showLineNumbersbooleanfalseWhether to show line numbers
highlightLinesnumber[][]Line numbers to highlight (1-based), given a background tint
copybooleantrueWhether to show the copy button
trafficbooleanfalseShow macOS-style red/yellow/green dots in the header bar
animatebooleantrueStagger a line-by-line fade in when it enters the viewport
maxHeightnumberMaximum height of the content area (px); beyond it, the area scrolls

Accessibility

  • When the user has "reduce motion" enabled at the system level, it renders statically without applying the line-by-line animation
  • The copy button carries an aria-label, and after a successful copy it transitions smoothly between the copy and check icons
  • The first render matches SSR and the animation is only enabled after mount, which avoids a hydration mismatch

On this page