Text Typing Animation in CSS
This article will show how to create text typing animation in HTML and CSS. This animation effect is helpful for creating attractive home page texts.
Step by Step guide to creating typewriter animation
- Create a <div> tag and set the classname “container”, and Inside it, create a <p> tag with some text and set the classname “text”. Make sure the width of the <p> element is only as long as the text itself.
- Then in CSS, select the “container” using the class selector and set the “display” property to “inline-block”
- Select “text” using the class selector and set the “font-size”, “letter-spacing”, and “font-family” as you wish. Set the “border-right” property to “5px solid” for the cursor. Then set the “white-space” property to “nowrap”, “overflow” property to “hidden” and “animation” property to “typing 2s steps(18), cursor .4s step-end infinite alternate” for animation work. Here, we set 18 steps because we have 18 characters in the <p> text. You should mention the correct amount of characters in your text including whitespace inside the steps() function.
- Then animate the “cursor” for blinking using keyframes like the below code.
- Animate the “typing” for typing effect using keyframes.
- See the below output, the text typing animation effect works successfully.
See the Pen
Text Typing Animation by Wonderdevelop (@wonderdevelop)
You can also altogether remove the steps() part to get a different style, as you can only pass the “animation” property to “typing 2s, cursor .4s step-end infinite alternate”. See the below output, our text typing animation works differently.
See the Pen
TypeWriting Text by Wonderdevelop (@wonderdevelop)