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:
<pre class='brush:php;toolbar:false;'>.typed-out {
overflow: hidden;
border-right: .15em solid orange;
font-size: 1.6rem;
width: 0;
}</pre>
<p>Please note that in order to make the typewriter effect effective, we have added the following: </p>
<ul>
<li>
<code>"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>and
) 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!

Here's a container with some child elements:

Flyout menus! The second you need to implement a menu that uses a hover event to display more menu items, you're in tricky territory. For one, they should

"The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect."- Tim Berners-Lee

In this week's roundup: datepickers are giving keyboard users headaches, a new web component compiler that helps fight FOUC, we finally get our hands on styling list item markers, and four steps to getting webmentions on your site.

The short answer: flex-shrink and flex-basis are probably what you’re lookin’ for.

In this week's look around the world of web platform news, Google Search Console makes it easier to view crawled markup, we learn that custom properties

The IndieWeb is a thing! They've got a conference coming up and everything. The New Yorker is even writing about it:


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.