This is a CSS typewriter effect that types like a real terminal: letters slide in one by one, the freshest one glows hot white and cools to green, then the line is erased and typed again. The typing itself is pure CSS โ one animated number registered with @property โ and a short script only splits your text into letters. Below: why the classic steps() version looks jerky, how @property makes it smooth, the settings and the gotchas.
Why this effect
I love terminals, and most typewriter effects online feel stiff: letters pop in on a fixed beat with
steps(). A real screen isn't like that โ the newest letter flares up and cools down, the line breathes. I wanted that warmth in pure CSS, with any text you throw at it. It's my favourite way to open a hero line or a loading screen without it looking like a cheap template.
What you'll build
A green terminal line with a block cursor. Typing speed, how long the line stays, the pause before it's retyped, size and colours are CSS variables. Type your own text in the preview โ it works with any text, emoji included.
How the typewriter effect works
1. The classic way: width and steps()
The usual CSS typing animation grows the width of a monospace line from 0 to 10ch in ten jumps. It works, but every letter just pops in, and the line has to be a single word of a known length:
h1 {
width: 10ch;
overflow: hidden;
animation: type 1.2s steps(10) infinite alternate;
}
@keyframes type {
from { width: 0; }
}
2. One number: how many letters are typed
Our version animates a single number, --n, from 0 to 10. A custom property normally can't be animated โ the browser doesn't know it's a number and just flips it at 50%. @property tells it the type, and then --n changes smoothly, frame by frame:
@property --n {
syntax: '<number>';
inherits: true;
initial-value: 0;
}
@keyframes type {
0% { --n: 0; }
27%, 75% { --n: 10; }
90%, 100% { --n: 0; }
}
One keyframe list gives the whole rhythm: type (0โ27%), hold (to 75%), erase faster (to 90%), wait.
3. Each letter reads --n
Every letter sits in its own <i> with its number --i. When --n passes that number, the letter grows from zero width and fades in. The * 1.5 makes it take two thirds of a step, so the next letter starts while this one is still settling:
i {
--k: clamp(0, (var(--n) - var(--i)) * 1.5, 1);
display: inline-block;
width: calc(var(--k) * 1ch);
opacity: var(--k);
}
The cursor is just h1::after โ it always stands right after the last visible letter, because the letters before it change width. It blinks with steps(1): a cursor really does snap on and off.
4. The hot letter
On an old phosphor screen a freshly drawn character is brighter for a moment. In the video version each letter runs a short pop animation, delayed so it starts exactly when the letter is typed: white with a glow for 0.07 s, back to green by 0.2 s:
i {
animation: pop 4.5s ease-out infinite;
animation-delay: calc(var(--i) * 0.1215s);
}
@keyframes pop {
0%, 1.5% {
color: #fff;
text-shadow: 0 0 10px #fff, 0 0 30px #b8ff9f;
}
4.4%, 100% {
color: #9be89a;
text-shadow: 0 0 0 transparent;
}
}
5. Any text: keyframes turned into formulas
The numbers above (10 letters, 27%, 0.1215 s) only fit one word. The customizable version replaces them with a clock: --tw-t runs from 0 to 1 once per cycle, and everything else is computed from it and from the number of letters --tw-len, which the script sets:
--tw-s: calc(var(--tw-t) * var(--tw-cycle)); /* seconds into the cycle */
--tw-n: clamp(0, min(
var(--tw-s) / var(--tw-speed),
var(--tw-len) - max(0, var(--tw-s) - var(--tw-typing) - var(--tw-hold)) / var(--tw-erase)
), var(--tw-len));
The first part of min() types, the second erases after the hold, clamp() keeps it between 0 and the length โ that's the pause. The hot letter is computed the same way, from the seconds since the letter was typed, and mixed in with color-mix():
--d: calc(var(--tw-s) - var(--tw-i) * var(--tw-speed));
--h: clamp(0, (0.2 - var(--d)) / 0.13, 1);
color: color-mix(in srgb, #fff calc(var(--h) * var(--h) * 100%), var(--tw-color));
The script itself only splits the text. It uses Intl.Segmenter rather than split(''), so an emoji or an accented letter stays one letter instead of breaking into pieces:
const letters = [...new Intl.Segmenter().segment(text)].map((part) => part.segment);
Make it yours
| Variable | Default | What it changes |
|---|---|---|
--tw-speed |
0.12 |
Seconds per letter. 0.05 is a fast typist, 0.25 is a slow, dramatic reveal. |
--tw-hold |
2.2 |
Seconds the typed line stays before it's erased. |
--tw-pause |
0.5 |
Seconds of empty line before it's typed again. |
--tw-size |
48px |
Text size. |
--tw-color |
#9be89a |
Letter colour. A pale shade looks like phosphor. |
--tw-glow |
#39ff14 |
Glow and cursor. Amber #ffb000 gives an old amber monitor. |
To change the text, change both the text and data-text.
Gotchas
- Use a monospace font. The box width is
letters ร 1ch; with a proportional font the cursor won't line up with the end of the line. - Keep it on one line. The line doesn't wrap (
white-space: pre), so long text on a phone needs a smaller--tw-size. @propertyis needed. It works in all current browsers. Without it--nwould jump straight from 0 to 10.- One heading, not a page. The clock restyles every letter each frame โ fine for a heading, wasteful for a long paragraph.
Accessibility
The letters are hidden from screen readers and the script puts the whole text into aria-label, so it's read once, not spelled. With prefers-reduced-motion the line is shown fully typed and the cursor stops blinking.
Where to use it
- Hero heading โ the first line visitors see, typed once or cycling through a few words.
- Terminal block on a landing page โ a fake command line for a developer tool or an API.
- Loading and 404 screens โ something alive to look at while nothing else is.
Keep it to one short line. A typewriter on a whole paragraph makes people wait to read.
Variations
- Type once. Give the line a huge hold,
--tw-hold: 99999: it types, then simply stays โ a nice hero heading entrance. - Amber terminal.
--tw-color: #ffd58a; --tw-glow: #ffb000. - Add a glitch. A terminal line that tears for a moment after it's typed โ see Glitch Text.
- Decode instead of type. Letters that run through random glyphs before they lock: Scramble Text.
FAQ
How do I make a typewriter effect in CSS without JavaScript?
The video version is pure CSS: each letter in its own <i> with a number, and one @property number animated by keyframes. JavaScript here only splits any text into letters for you.
Why do the letters in my typing animation jump instead of sliding?
That's steps() on width. Animate a registered number with @property instead and derive each letter's width and opacity from it.
Is there a React typewriter effect?
You don't need a React library for this: render the letters as <i style={{ "--tw-i": i }}> in your component and keep this CSS. The animation runs in the browser, not in React state, so it costs no re-renders.
How do I stop the cursor after typing?
In the classic width version the cursor is the box's right border, so it only sits right after the last letter when the width is exactly the text length in ch. Here the cursor is ::after, so it always stops right after the last typed letter. To type once and keep the line, set --tw-hold: 99999; to stop the blinking too, add .tw-type::after { animation: none; }.
How do I type multiple lines?
The width trick can't wrap, so every line is its own element. Put each line in its own .tw-type, type it once (--tw-hold: 99999), and delay the second line by the time the first one takes โ letters ร speed:
.tw-line-2 {
animation-delay: calc(10 * 0.12s); /* 10 letters in line 1 */
}
.tw-type:not(:last-child)::after {
display: none; /* one cursor, on the last line */
}
How do I loop several words (type, delete, type)?
CSS can't change the text, so this needs a few lines of JavaScript. Wrap the splitting code in a function split(text); when the clock finishes a cycle, the line is empty โ that's the moment to swap the word and restart the clock, because its length depends on the number of letters:
const words = ["DESIGNER", "DEVELOPER", "MAKER"];
let w = 0;
line.addEventListener("animationiteration", (e) => {
if (e.animationName !== "tw-clock") return;
w = (w + 1) % words.length;
split(words[w]);
line.style.animation = "none";
line.offsetWidth; // restart the clock with the new length
line.style.animation = "";
});
Can I copy and paste the code?
Yes. Type your text in "Your text", set speed, hold and colours with the sliders, then copy the HTML, CSS and JS with the buttons at the top of the page, or download them as a .zip โ the page works as a small typewriter effect generator.