How to Create a CSS Typewriter Effect for Your Website
Pure CSS creates engaging typewriter text effects
Core points:
- CSS typewriter effect makes the website content more dynamic and attractive by gradually displaying text, and can be used for login pages, personal websites and code demonstrations. The
- Typewriter effect can be created by using the CSS
steps()
function to change the width of the text element from 0% to 100%, and to simulate the cursor of "Putout" the text through animation. - The typing effect can be adjusted by increasing or decreasing the number of steps and duration of the typing animation to accommodate longer or shorter text. The
- Typewriter effect can be used in conjunction with the flashing cursor animation to enhance the effect, and the cursor can be customized by adjusting its
border-right
properties, color, flicker frequency, etc.
This article will guide you how to create dynamic, more attractive website text typewriter effects using pure CSS.
The typewriter effect simulation text is displayed word by word, just like typing in real time in front of you.
Adding typewriter effects in text snippets helps attract website visitors and keep them interested in continuing to read. Typewriter effects can be used for a variety of purposes, such as creating engaging login pages, call-to-action elements, personal websites, and code presentations.
Easy to create typewriter effects
Creating a typewriter effect is very simple, you only need to have the basic knowledge of CSS and CSS animations to understand this tutorial.
The working principle of typewriter effect is as follows:
- Typewriter animation will gradually change the width of the text element from 0% to 100% by using the CSS
steps()
function, thus displaying our text element. - The flashing animation will simulate the cursor of "Putout" the text.
Create a typewriter effect webpage
First, let's create a web page for the typewriter demonstration. It will contain a <div> container for typewriter text, with class name <code>typed-out
:
<!doctype html> <html> <head> <title>Typewriter effect</title> <style> body{ background: navajowhite; background-size: cover; font-family: 'Trebuchet MS', sans-serif; } </style> </head> <body> <div class="container"> <div class="typed-out">Web Developer</div> </div> </body> </html>
Style style for typewriter text container
Now that we have the layout of the web page, let's style for <div>
with the "typed-out" class:
.typed-out { overflow: hidden; border-right: .15em solid orange; font-size: 1.6rem; width: 0; }
Please note that in order to make the typewriter effect effective, we have added the following:
"overflow: hidden;"
and"width: 0;"
make sure that the text content is not displayed until the typing effect begins."border-right: .15em solid orange;"
, create the typewriter cursor.
Before making a typing effect, in order to stop the cursor after the last letter of the typed-out
element is fully typing (like a typewriter or word processor), we will create a container for the typed-out
element and add display: inline-block;
:
.container { display: inline-block; }
Create display text animation
Typewriter animation will create a verbatim effect for text within the typed-out
element to be displayed. We will use @keyframes
CSS animation rules:
<!doctype html> <html> <head> <title>Typewriter effect</title> <style> body{ background: navajowhite; background-size: cover; font-family: 'Trebuchet MS', sans-serif; } </style> </head> <body> <div class="container"> <div class="typed-out">Web Developer</div> </div> </body> </html>
As you can see, all this animation does is change the width of the element from 0% to 100%.
Now, we include this animation in our typed-out
class and set its animation orientation to forwards
to ensure that the text element does not return to width: 0
after the animation is over:
.typed-out { overflow: hidden; border-right: .15em solid orange; font-size: 1.6rem; width: 0; }
Our text elements will be displayed from left to right in a smooth manner:
Add steps to achieve typewriter effect
So far, our text has been displayed, but it is a smooth way to not display the text verbatim. This is a start, but obviously it doesn't look like the typewriter effect.
In order for this animation to display our text elements verbatim or step by step (just like a typewriter), we need to split the typing animation contained in the typed-out
class into steps so that it looks like it is typing out. This is where the CSS steps()
function comes into play:
.container { display: inline-block; }
As you can see, we use the CSS steps()
function to divide the typing animation into 20 steps.
Adjust the steps for longer typing
To adjust longer text, you need to increase the steps and duration of the typing animation.
Adjust the steps for shorter typing
To adjust shorter text, you need to reduce the steps and duration of typing animations.
Create and set flashing cursor animation
Apparently, the original mechanical typewriters did not have a flashing cursor, but adding it in to mimic the flashing cursor effect of more modern computer/word processors has become tradition. The flashing cursor animation helps make the imprinted text stand out from the static text elements.
To add a flashing cursor animation to our typewriter animation, we will first create a flashing animation:
@keyframes typing { from { width: 0 } to { width: 100% } }
In our webpage, this animation will change the border color of the typed-out
element border (used as the cursor for typewriter effects) from transparent to orange.
We include this animation in the rules of the typed-out
class and set its animation direction property to infinite
to make the cursor disappear and reappear indefinitely every 0.8 seconds:
.typed-out{ overflow: hidden; border-right: .15em solid orange; white-space: nowrap; font-size: 1.6rem; width: 0; animation: typing 1s forwards; }
Code to adjust the flashing typing effect
We can make the cursor thinner or thicker by adjusting its border-right: .15em solid orange;
attribute, or you can make the cursor color differently, give it border-radius
, adjust its flicker frequency, etc.
Elements of Combining Typewriter Text Animation
Now that you know how to make a typewriter effect in CSS, it's time to demonstrate some practical and relevant use cases for this typewriter effect.
Conclusion
In this article, we understand how easy it is to create animated "typewriter" text using CSS. This typing effect can definitely add fun and fun to your page.
However, it may be worth a gentle warning at the end. This technique is best used for a small amount of non-critical text, just to add a little extra fun. But be careful not to over-rely rely on it, as there are some limitations to using CSS animations like this. Make sure to test your typewriter text on various devices and viewport sizes, as the results may vary by platform. Also consider end users who rely on assistive technology, ideally, some usability tests can be performed to ensure you don't cause inconvenience to users. Because you can do something with pure CSS doesn't necessarily mean you should. If typewriter effects are important to you and you want to use it for more critical content, maybe at least consider a JavaScript solution, too.
Anyway, I hope you enjoyed this post and it gets you to think about what other cool things you can do with CSS animations to add fun and fun to your page.
Frequently Asked Questions about Creating CSS Typewriter Effects
Finally, let's answer some of the most common questions about how to create typewriter effects in CSS.
- What is the typewriter effect?
"Typewriter Effect" is an animation technique that makes a string of text appear word by word on the screen as if it is being typed in real time by the typewriter. This effect is usually created with JavaScript, but it can also be implemented using CSS only, as shown in this article.
- What is typewriter animation?
The typewriter prints text one letter at a time. Typewriter animation is an animation that imitates typewriter typing, presenting text with one letter at a time. It is a popular animation effect on many web pages.
- How to make animated text typing in CSS?
Modern CSS provides a variety of tools for creating animations, including animation
, @keyframes
, steps()
. These tools are used to gradually display text that is first hidden through the overflow
attribute.
- How to use CSS to create customizable typewriter animations?
Creating customizable typewriter animations with CSS involves using keyframes and CSS properties to control how text looks and behaves when typing on the screen. You can make it customizable by exposing some animation parameters as CSS variables (custom properties) so that you can easily change them in your stylesheet. For example:
<!doctype html> <html> <head> <title>Typewriter effect</title> <style> body{ background: navajowhite; background-size: cover; font-family: 'Trebuchet MS', sans-serif; } </style> </head> <body> <div class="container"> <div class="typed-out">Web Developer</div> </div> </body> </html>
) to make the animation customizable. You can change the default values by modifying these properties. --typewriter-text
--typewriter-duration
- How to stop the cursor after the last letter of the
- element is fully printed?
typed-out
To stop the cursor of the last letter of the
attribute: typed-out
<!doctype html> <html> <head> <title>Typewriter effect</title> <style> body{ background: navajowhite; background-size: cover; font-family: 'Trebuchet MS', sans-serif; } </style> </head> <body> <div class="container"> <div class="typed-out">Web Developer</div> </div> </body> </html>
In the above CSS, the typewriter animation gradually increases the width of the elements in the container, effectively typing out text. The .typewriter
property is set to animation-fill-mode
to ensure that the animation remains final (completely played out) after completion. With this setting, the cursor will flash at the forwards
element after it is fully printed. typed-out
- What are some website examples that effectively use typewriter effects?
The above is the detailed content of How to Create a CSS Typewriter Effect for Your Website. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

It's out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

With the recent climb of Bitcoin’s price over 20k $USD, and to it recently breaking 30k, I thought it’s worth taking a deep dive back into creating Ethereum

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That's like this.

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

I'd say "website" fits better than "mobile app" but I like this framing from Max Lynch:

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...
