Getting Started
The Typewriter plugin enhances Expressive Code blocks on your website by adding terminal typing animations to code blocks. Commands appear character-by-character with a blinking cursor, while output appears instantly.
This guide will show you how to add it to your website.
Set-up
Section titled “Set-up”-
Install the
expressive-code-typewriterdependency using your preferred package manager:Terminal window npm i expressive-code-typewriterTerminal window pnpm add expressive-code-typewriterTerminal window yarn add expressive-code-typewriter -
Add the plugin to your site’s Expressive Code configuration:
astro.config.mjs import { defineConfig } from 'astro/config';import astroExpressiveCode from 'astro-expressive-code';import { pluginTypewriter } from 'expressive-code-typewriter';export default defineConfig({integrations: [astroExpressiveCode({plugins: [pluginTypewriter()],}),],});astro.config.mjs import { defineConfig } from 'astro/config';import starlight from '@astrojs/starlight';import { pluginTypewriter } from 'expressive-code-typewriter';export default defineConfig({integrations: [starlight({title: 'My Starlight site',expressiveCode: {plugins: [pluginTypewriter()],},}),],});next.config.mjs import createMDX from '@next/mdx';import rehypeExpressiveCode from 'rehype-expressive-code';import { pluginTypewriter } from 'expressive-code-typewriter';/** @type {import('rehype-expressive-code').RehypeExpressiveCodeOptions} */const rehypeExpressiveCodeOptions = {plugins: [pluginTypewriter()],};/** @type {import('next').NextConfig} */const nextConfig = {reactStrictMode: true,pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],};const withMDX = createMDX({extension: /\.mdx?$/,options: {remarkPlugins: [],rehypePlugins: [// The nested array structure is required to pass options// to a rehype plugin[rehypeExpressiveCode, rehypeExpressiveCodeOptions],],},});export default withMDX(nextConfig);ec.config.mjs import { pluginTypewriter } from 'expressive-code-typewriter';export default {plugins: [pluginTypewriter()],}; -
That’s it! Now add the
typedmeta option to any code block to enable the typing animation.
Basic Usage
Section titled “Basic Usage”Add typed to your code block’s meta string to enable the typing effect:
```bash typed$ npm install my-packageInstalling dependencies...Done!```Lines starting with $ (the default prompt) type character-by-character, while other lines appear instantly.
For more information on how to configure the plugin, see the Configuration page.
Support
Section titled “Support”This plugin is open-source software licensed under the MIT license. If you run into any bugs, please report issues on GitHub.