CSS Typing Effect: How Typewriter Text and Cursor Blinking Work

PublishedToolCSS Typing Text Effect Generator

Contents
  1. The typing effect: why does it look like JavaScript?
  2. How to verify it: build it yourself in code
  3. Common sticking points
  4. Recap
  5. Core technical mechanism: the CSS masking reveal model and step functions
  6. Comparison Table: Ways to Build a Text Typing Effect
  7. 5 Common CSS Typing Mistakes
  8. Pixel-Perfect Typing Effect: A 5-Step Workflow
  9. 7 Tips for Typing Animations
  10. Decision Tree: How to Choose a Text Reveal Animation
  11. Terminology Cheat Sheet
  12. Frequently Asked Questions

When you see a line of text with a typing effect, it looks like JavaScript is drawing it in one character at a time. The blinking cursor next to it makes it feel even more that way. But this effect is built with nothing but two pure CSS animations.

Summary ① The characters appearing one by one isn't text being added — it's a CSS animation that grows the element's width from 0 to the full character count ② overflow: hidden hides the characters outside the width that hasn't grown yet, so the text looks like it's appearing as the width increases ③ The cursor beside it is a separate border-right plus a blink animation. It just runs at the same time as the typing animation — the two are different effects

The typing effect: why does it look like JavaScript?

Because the characters appear one after another with a delay, most people assume JavaScript is appending the string one character at a time with something like setInterval. Plenty of libraries really do implement it that way.

But you can create the same illusion with CSS alone. Put the entire text inside the element from the start, then animate the element's width from 0 to the full text width. If you set overflow: hidden on the element, the characters in the part the width hasn't reached yet don't show on screen.

As the width grows little by little, the hidden characters behind it are revealed in order. So in reality you're not adding text — a "cover" is just sliding out of the way. And if that width increase runs smoothly, the reveal looks like it's flowing pixel by pixel instead of character by character.

That's where CSS's steps() timing function becomes the key. With steps(character count, end), the width animation doesn't glide — it jumps in exactly as many hard steps as there are characters. Pair that with a monospace (fixed-width) font, where every character has the same width, and the CSS unit ch, which means the width of one character, and one step matches exactly one character.

How to verify it: build it yourself in code

First, on the element that wraps the text, set overflow: hidden, white-space: nowrap, and font-family: monospace. You need to block line breaks and overflow for the width animation to behave the way you intend.

Next, create a keyframes rule that grows the width from 0 to the character count (for example, 20ch for 20 characters), and set duration and steps(character count, end) in the animation property. If that value doesn't match the actual character count, you get a mismatch: either the animation keeps running after all the text is visible, or the animation finishes while the last character still isn't showing.

The cursor is built separately. Draw a vertical line with border-right, then attach a blink-caret animation that toggles border-color between transparent and the cursor color, chaining it on with a comma. You need step-end so the cursor snaps on and off instead of fading gradually.

Check it with our tool. Enter your text, typing speed, and cursor color, and it immediately generates CSS and HTML code calculated on these same principles, with a live preview.

CSS Typing Text Effect Generator

Free · no sign-up · generate CSS right in your browser

Common sticking points

SituationCause
Changing the text doesn't replay it from the startThe width animation starts when the element is newly rendered, so you have to remount the element when the text changes for it to replay from the beginning
Typing looks unnatural in a normal fontEach character has a different actual width, so it doesn't match the ch width — the text shows up early or leaves extra space at the end
The steps() number doesn't match the character countThe animation's pace and the characters actually visible fall out of sync, so the last character shows up late or is revealed too early
The cursor sits there without blinkingYou added border-right but didn't attach a separate blink-caret animation along with it

Most of the situations in the table come down to a mismatch between "the steps value of the width animation" and "the actual character count." If you always calculate both values in the same place, that mismatch can't happen.

Recap

In a typing effect, characters appearing one by one isn't text being added — it's a CSS animation that grows, in steps() units, the width of an element whose overflow is hidden by overflow: hidden. The cursor blinking beside it is just a border-right with a separate blink animation added on top.

If all you need is one line of text typed once and repeated, these two animations together are enough — no JavaScript required.

CSS Typing Text Effect Generator

Free · no sign-up · generate CSS right in your browser


Core technical mechanism: the CSS masking reveal model and step functions

How does it look like characters are being added one at a time without JavaScript? It's thanks to the CSS Width Masking Reveal Model.

1. The masking illusion (Overflow Masking)

The text isn't actually being added to the DOM dynamically. It exists in the DOM complete from the start. It's just that overflow: hidden on the parent container clips and hides the text outside the current width. When you gradually grow the width with a @keyframes typing { from { width: 0; } to { width: Nch; } } animation, the hidden characters are revealed one after another.

2. The steps(N, end) step timing function

The steps() function is what makes a width that would otherwise stretch out smoothly instead break into hard "one character" increments. Expressed as a formula, it looks like this: At time tk = k/N · T,   width jumps to k/N × Nch = kch Over the total time T, the width makes exactly N discrete jumps in a staircase pattern, and each jump increases the width by exactly 1ch.

3. Why the ch unit and monospace fonts are essential

The CSS unit 1ch means the width of the digit "0" in the current font.

  • Monospace font: Every character (A, i, W, and so on) has the same width of 1ch. So the rule "1 step of width increase = 1 character revealed" holds perfectly.
  • Proportional font: Widths differ — "i" is about 0.3ch, "W" is about 1.2ch. Because of that, the step increment and the character width fall out of sync and the typing illusion breaks.

The cursor blinking at the end of the text is a completely independent effect, separate from the text animation. It's usually drawn using the right border of the text container (border-right: 3px solid). Then you attach an animation that switches border-color between transparent and the chosen color, making sure to use step-end so the color snaps on and off like a blade rather than fading.


Comparison Table: Ways to Build a Text Typing Effect

Here's how pure CSS stacks up against JavaScript-based approaches.

ApproachHow it worksJS dependencyFont constraintsMulti-line supportCustomization flexibilitySEO text crawling
Pure CSS Width MaskReveals text by animating a cover using steps() and the ch unit0KB (none)Monospace requiredHard (single line recommended)LowPerfect (in the DOM from the start)
JS innerHTML AppendAdds text to the DOM one character at a time with setIntervalHighNone (any font works)ModerateVery highCan be an issue (client-side rendering)
GSAP SplitTextSplits text into pieces and staggers the delay on eachHigh (library required)None (any font works)ExcellentVery highPerfect
Typed.js LibraryA well-known JS library built specifically for typing animationsHigh (library required)None (any font works)ExcellentHighest (backspace support, etc.)Depends on configuration
SVG stroke-dashoffsetAn SVG path effect that looks like handwriting being drawn0KB – low(Depends on the SVG path)Not possibleLimited to path drawingText not exposed

5 Common CSS Typing Mistakes

These are the five mistakes that come up most often when you write a typing animation.

  1. Using a proportional font: Character widths aren't uniform, so letters look half-cut in the middle of the animation.
  2. Miscounting the number of steps: People forget that Korean, Japanese, and Chinese characters take up about twice the width of a Latin letter (about 2ch), so the animation cuts off partway through.
  3. Using smooth easing (ease, linear): If you use a smooth timing function instead of steps(N, end), you don't get typing — you get a slide-mask effect where the text glides in sideways.
  4. Leaving out white-space: nowrap: Once the text gets long enough to wrap, the horizontal width-masking view falls apart completely.
  5. Leaving out animation-fill-mode: forwards: Without this property, the animation snaps back to its initial state (width: 0) as soon as it hits 100%, so the finished text vanishes right in front of you.

Pixel-Perfect Typing Effect: A 5-Step Workflow

  1. Set up the text container: Give the element wrapping your text overflow: hidden; white-space: nowrap; so it acts as a cover and prevents line breaks.
  2. Apply a monospace font: Set font-family: 'Fira Code', 'Courier New', monospace; on the element so every character has the same width.
  3. Count the characters (N) accurately: Count the total number of characters, including spaces. Latin letters and digits count as 1 each; CJK characters such as Korean and Chinese count as 2 each.
  4. Hook up the typing keyframes to the steps animation: Define @keyframes typing { from { width: 0 } to { width: Nch } } and apply animation: typing 2s steps(N, end) forwards; to the element.
  5. Add an independent blinking cursor: Draw the cursor on the same element with border-right: 2px solid;, define @keyframes blink-caret, and add a blinking animation on a separate assignment using step-end.

7 Tips for Typing Animations

  1. Always set forwards mode: If you want the text to stay on screen after typing finishes, never forget animation-fill-mode: forwards.
  2. Always use step-end for the cursor blink: To get that crisp terminal-cursor blink, use step-end instead of ease.
  3. Add an initial delay: Give readers a moment to get ready by adding something like animation-delay: 1s before the typing starts. It feels much more natural.
  4. Handle CJK characters: When you apply this to Korean or Japanese, increase the target width to N2ch and set steps to N2. You can also use em, a unit relative to font size, to match the width manually.
  5. Chain multiple lines: To type out several lines, give each line element a progressively longer animation-delay so the next line starts right as the line above finishes.
  6. Hide the cursor after typing ends: If an endlessly blinking cursor bothers you, set a repeat count like animation: blink-caret 0.75s step-end 5 so the cursor blinks a few times and then disappears.
  7. Use a generator: If writing the CSS by hand and counting characters is a hassle, use the free generator web tool on this page to get code with the character count and steps already calculated for you.

Decision Tree: How to Choose a Text Reveal Animation

Which approach should your project use?

  • Q1. Is the font you have to use proportional?
    • Yes ➔ GSAP SplitText or a JS-based library (Typed.js)
    • No (monospace is fine) ➔ Go to Q2
  • Q2. Does the text need to wrap across multiple lines automatically?
    • Yes ➔ A JS-based library
    • No (single line or manual line breaks) ➔ Go to Q3
  • Q3. Do you need a pen-on-paper handwriting effect?
    • Yes ➔ SVG stroke-dashoffset handwriting animation
    • No ➔ Pure CSS steps()-based typing effect (best performance, zero dependencies)

Terminology Cheat Sheet

  • Typewriter Effect: A visual effect where text appears one character at a time, like a mechanical typewriter or a terminal window.
  • Step function (steps()): A CSS animation timing function that cuts between frames instantly a set number of times instead of smoothly interpolating in-between frames.
  • ch unit (Character Unit): A CSS font-relative length unit. It equals the width of the "0" digit in the current font.
  • Monospace Font: A font designed so every character has the same horizontal width (e.g., Courier, Fira Code).
  • Overflow Masking: A technique that uses overflow: hidden to hide anything outside a specific area.
  • Cursor Blink: The effect where a thin rectangular or line-shaped cursor at the end of the typed text appears and disappears at regular intervals.
  • Width Animation: A CSS transition or animation where the width grows from width: 0 to a target size.
  • CJK double-byte characters: Chinese, Japanese, and Korean characters, which take up roughly twice the space of Latin letters even in a monospace setting.

Frequently Asked Questions

Q1. Why is a monospace font a must-have for a typing effect, not just a nice-to-have?

A1. The steps(N) function splits the specified target width (Nch) into exactly N equal-length intervals. If each character's actual width differs, some characters are narrower than one step, so part of the next character shows too, while wider characters aren't fully revealed yet. For the formula of 1 step = 1 character revealed to hold, every character has to be exactly 1ch wide.

Q2. How do you handle CJK characters, like Korean, that take up 2ch of width?

A2. There are two approaches. First, double both the target width and the steps value. For example, for 10 Korean characters, use width: 20ch; steps(20). Second, use the em unit (the font size itself) instead of ch and tune the ratio by hand. Lately, to fully support proportional fonts and Korean, a common trend is to mix in a JS approach that appends characters one at a time instead of relying on pure CSS.

A3. A real computer terminal or typewriter cursor only exists in On/Off states, like a digital signal. If you use ease or linear to smoothly change opacity from 0 to 1, it looks less like a cursor and more like a broken fluorescent light or a breathing LED, which seriously hurts immersion. Using step-end, where the color switches abruptly, is the key detail that keeps the terminal realism alive.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. CSS typing text effect with steps() and ch units, explainedHow steps(N) easing and the ch unit build a pure-CSS typewriter effect, how to size width and steps, plus cursor timing and font caveats.
  2. Curved Text Logo: Bend Text Into a Circle With SVGSee why curved logo text follows an SVG path instead of a font, and how to place text on an arc with textPath, startOffset, and text-anchor.
  3. Duotone effect: how a photo ends up with just two colorsA duotone keeps only a photo's brightness, then repaints it between two colors. Here's the gradient map math behind the look, and how to try it.
  4. Emoji favicon looks broken? Why family and flag emoji get cutSome emoji look sliced in a favicon. Here's why the tool uses only 4 code points, which emoji survive, and how to count them in your browser console.
  5. Screen Color Picker Missing in Safari? How to Get Pixel ColorsThe eyedropper button on screen color pickers only appears in Chromium browsers. Here's how to read a pixel's HEX, RGB, HSL, and HSV values without it.
  6. flex-grow vs flex-shrink: how leftover space splits 1:2See when flex-grow and flex-shrink actually kick in, what flex-basis defaults to, and the math that splits 900px of free space into an exact 1:2.

Related tools