Animated Code Block

Code block with a typewriter reveal, syntax highlighting via Prism, and swappable color themes.

feature-card.tsx

Animated Code Block types out source code character by character inside a styled React panel, with Prism syntax highlighting and several built-in themes. Line highlights, custom fonts, and playback speed are all props, so the same component can narrate a tutorial walkthrough, animate an API example on a landing page, or bring a README snippet to life in a hero section. Built with React and Tailwind CSS.

Installation

Examples

Parchment

feature-card.tsx

Terminal

feature-card.tsx

Minimal

feature-card.tsx

Usage

import { AnimatedCodeBlock } from "@/components/ui/animated-code-block";
<AnimatedCodeBlock
  code={`console.log("Hello world!");`}
  theme="dark"
  typingSpeed={50}
  showLineNumbers={true}
  autoPlay={true}
/>

Props

Animated Code Block

PropTypeDefaultDescription
codestringRequiredThe code to display and animate
theme"dark" | "terminal" | "minimal" | "parchment""dark"The visual theme
typingSpeednumber50The speed of the typing animation in milliseconds
showLineNumbersbooleantrueWhether to show line numbers
highlightLinesnumber[][]Array of line numbers to highlight
titlestring"Code Example"Title to display in the header
autoPlaybooleanfalseWhether to start the animation automatically
loopbooleanfalseWhether to loop the animation
showControlsbooleantrueWhether to show play/pause and copy controls
onCopy() => voidundefinedCallback function when code is copied
classNamestring""Additional CSS classes to apply
languagestring"javascript"Language for syntax highlighting (e.g., javascript, python, etc.)