A typewriter effect reveals text a character at a time. Use CSS for a short, fixed line; use JavaScript when you need dynamic text, custom timing, or sequencing. In either case, keep the complete message available and show it immediately when a visitor prefers reduced motion.
Choose CSS or JavaScript
| Approach | Best for | Trade-off |
|---|---|---|
CSS width reveal with steps() |
A short line whose length and layout are predictable | Clipping, fixed-width assumptions, and preventing wrapping can make responsive layouts harder. |
| JavaScript character reveal | Dynamic strings, controlled character timing, or sequenced text and cursor animation | You must manage animation behavior, including the reduced-motion preference. |
| Existing library or hosted example | Starting from an existing implementation rather than building the animation yourself | Check maintenance, compatibility, licensing, and accessibility behavior before adding a dependency; the examples cited here do not establish a best library. |
The effect is decorative, not a reason to withhold essential text. Keep your full message in the page and treat the animation as presentation.
Create a simple CSS typewriter effect
A CSS-only approach can reveal a line by animating its width in discrete steps. The cited example combines a fixed width, hidden overflow, no wrapping, and stepped timing. See the Pure CSS typewriter example for the pattern.
.typewriter {
display: inline-block;
overflow: hidden;
white-space: nowrap;
border-right: 2px solid currentColor;
animation: typing 3s steps(24, end), blink 0.7s step-end infinite;
}
@keyframes typing {
from { width: 0; }
to { width: 24ch; }
}
@keyframes blink {
50% { border-color: transparent; }
}
Replace 24 with a value suited to the text. This approach assumes a single line and a known character width; it is not a general solution for arbitrary-length or wrapping text. Test the result at narrow viewport sizes, and do not use clipping to hide content from assistive technology.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11#1 Best Overall
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Use JavaScript when timing or text is dynamic
JavaScript is a better fit when the string changes, characters need individualized timing, or several elements must appear in sequence. Motion provides an example that animates text and a cursor with its JavaScript animate function: Motion typewriter example. Its typewriter tutorial offers a further implementation reference.
For a custom implementation, keep the complete message in the document and update a visual presentation of it rather than making the only copy exist after a delayed sequence. Provide a way to finish or skip a long animation if waiting would obstruct the task.
Honor reduced-motion preferences
When a visitor requests reduced motion, show the complete message without the character reveal and stop or remove a decorative blinking cursor. W3C’s JavaScript technique recommends checking the prefers-reduced-motion media query before starting an animation; its CSS technique describes using the same preference to prevent CSS-driven motion.
For CSS animation
Override the animation for users who request reduced motion. For example:
Recommended Free Tools
Rank #3
@media (prefers-reduced-motion: reduce) {
.typewriter {
width: auto;
overflow: visible;
border-right: 0;
animation: none;
white-space: normal;
}
}
Ensure the full text is present in the markup so removing the animation reveals the intended message. W3C documents this CSS approach in Technique C39.
For JavaScript animation
Check the preference before launching the character sequence. W3C’s example uses window.matchMedia("(prefers-reduced-motion: no-preference)") to determine whether to run motion. If the preference is reduced, render the finished text instead. See Technique SCR40 and MDN’s prefers-reduced-motion reference.
Rank #4
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Make the effect usable, not just animated
- Keep important instructions, labels, and status information readable without waiting for the animation.
- Use the cursor only as a visual cue; do not let it obscure the text or imply that more content is essential.
- Check that the complete message is available to assistive technology and that the animation does not repeatedly announce each character.
- Test both the normal presentation and reduced-motion fallback, including at smaller screen widths.
A project such as typewriter.js is another implementation to inspect. Its suitability depends on its current maintenance, compatibility, license, and accessibility behavior, which should be checked before adoption.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

