Typewriter Component for Astro

SEO Optimized and Screen Reader Friendly

Features

Installation

Terminal window
npm install astro-typewriter
# or
yarn add astro-typewriter
# or
pnpm add astro-typewriter

Usage

Basic example

---
import Typewriter from "astro-typewriter";
---
<Typewriter messages={["Hello World", "This was easy"]} />

With emojis

---
import Typewriter from "astro-typewriter";
---
<Typewriter
messages={["Hello Emojis ๐Ÿ‘‹", "โค๏ธ๐Ÿงก๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ"]}
style="line-height: 1.2em"
/>

Add line-height: 1.2em to prevent layout shifts. → More info

With inherited styles

---
import Typewriter from "astro-typewriter";
---
<div class="fancy">
<Typewriter messages={["Hello World", "This was easy"]} />
</div>
<style>
.fancy {
color: #b33e66;
text-decoration: underline;
}
</style>

With class styles

---
import Typewriter from "astro-typewriter";
---
<Typewriter messages={["Hello World", "This was easy"]} class="typewriter" />
<style>
.typewriter {
background: linear-gradient(to right, #121fcf 0%, #cf1512 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>

With inline styles

---
import Typewriter from "astro-typewriter";
---
<Typewriter
messages={["Hello World", "This was easy"]}
style="color: green; font-family: monospace"
/>

With custom cursor



---
import Typewriter from "astro-typewriter";
---
<Typewriter messages={["Hello World", "This was easy"]} class="big" />
<br />
<Typewriter messages={["Hello World", "This was easy"]} class="emoji" />
<br />
<Typewriter messages={["Hello World", "This was easy"]} class="no-blink" />
<style>
.big::part(typewriter)::after {
color: lime;
width: 0.5em;
height: 1.5em;
transform: translateY(0.4em);
}
.emoji::part(typewriter)::after {
content: "โค๏ธ";
background: transparent;
}
.no-blink::part(typewriter)::after {
animation: none;
}
</style>

With custom speeds

---
import Typewriter from "astro-typewriter";
---
<Typewriter
messages={["I am a slow typer."]}
writeSpeed={250}
deleteSpeed={50}
waitWritten={3000}
waitDeleted={2000}
/>

All speeds are in milliseconds.

Attributes