Home Web Front-end CSS Tutorial How to Create a CSS Typewriter Effect for Your Website

How to Create a CSS Typewriter Effect for Your Website

Feb 08, 2025 am 10:20 AM

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.

How to Create a CSS Typewriter Effect for Your Website

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:

In this CSS code, we define custom properties (
<!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
element in the CSS typewriter animation, you can use the CSS animation and 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?
Typewriter animations are often used on sites such as portfolio sites, especially on designers and developers’ websites, which are used to highlight key skills and add creative sense to the page, thereby attracting the reader’s attention. Typewriter effects are sometimes used in blog websites and login pages as well as product demonstrations.

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
CSS tutorial for creating loading spinners and animations CSS tutorial for creating loading spinners and animations Jul 07, 2025 am 12:07 AM

There are three ways to create a CSS loading rotator: 1. Use the basic rotator of borders to achieve simple animation through HTML and CSS; 2. Use a custom rotator of multiple points to achieve the jump effect through different delay times; 3. Add a rotator in the button and switch classes through JavaScript to display the loading status. Each approach emphasizes the importance of design details such as color, size, accessibility and performance optimization to enhance the user experience.

Addressing CSS Browser Compatibility issues and prefixes Addressing CSS Browser Compatibility issues and prefixes Jul 07, 2025 am 01:44 AM

To deal with CSS browser compatibility and prefix issues, you need to understand the differences in browser support and use vendor prefixes reasonably. 1. Understand common problems such as Flexbox and Grid support, position:sticky invalid, and animation performance is different; 2. Check CanIuse confirmation feature support status; 3. Correctly use -webkit-, -moz-, -ms-, -o- and other manufacturer prefixes; 4. It is recommended to use Autoprefixer to automatically add prefixes; 5. Install PostCSS and configure browserslist to specify the target browser; 6. Automatically handle compatibility during construction; 7. Modernizr detection features can be used for old projects; 8. No need to pursue consistency of all browsers,

What is the difference between display: inline, display: block, and display: inline-block? What is the difference between display: inline, display: block, and display: inline-block? Jul 11, 2025 am 03:25 AM

Themaindifferencesbetweendisplay:inline,block,andinline-blockinHTML/CSSarelayoutbehavior,spaceusage,andstylingcontrol.1.Inlineelementsflowwithtext,don’tstartonnewlines,ignorewidth/height,andonlyapplyhorizontalpadding/margins—idealforinlinetextstyling

Styling visited links differently with CSS Styling visited links differently with CSS Jul 11, 2025 am 03:26 AM

Setting the style of links you have visited can improve the user experience, especially in content-intensive websites to help users navigate better. 1. Use CSS's: visited pseudo-class to define the style of the visited link, such as color changes; 2. Note that the browser only allows modification of some attributes due to privacy restrictions; 3. The color selection should be coordinated with the overall style to avoid abruptness; 4. The mobile terminal may not display this effect, and it is recommended to combine it with other visual prompts such as icon auxiliary logos.

Creating custom shapes with css clip-path Creating custom shapes with css clip-path Jul 09, 2025 am 01:29 AM

Use the clip-path attribute of CSS to crop elements into custom shapes, such as triangles, circular notches, polygons, etc., without relying on pictures or SVGs. Its advantages include: 1. Supports a variety of basic shapes such as circle, ellipse, polygon, etc.; 2. Responsive adjustment and adaptable to mobile terminals; 3. Easy to animation, and can be combined with hover or JavaScript to achieve dynamic effects; 4. It does not affect the layout flow, and only crops the display area. Common usages are such as circular clip-path:circle (50pxatcenter) and triangle clip-path:polygon (50%0%, 100 0%, 0 0%). Notice

How to create responsive images using CSS? How to create responsive images using CSS? Jul 15, 2025 am 01:10 AM

To create responsive images using CSS, it can be mainly achieved through the following methods: 1. Use max-width:100% and height:auto to allow the image to adapt to the container width while maintaining the proportion; 2. Use HTML's srcset and sizes attributes to intelligently load the image sources adapted to different screens; 3. Use object-fit and object-position to control image cropping and focus display. Together, these methods ensure that the images are presented clearly and beautifully on different devices.

Demystifying CSS Units: px, em, rem, vw, vh comparisons Demystifying CSS Units: px, em, rem, vw, vh comparisons Jul 08, 2025 am 02:16 AM

The choice of CSS units depends on design requirements and responsive requirements. 1.px is used for fixed size, suitable for precise control but lack of elasticity; 2.em is a relative unit, which is easily caused by the influence of the parent element, while rem is more stable based on the root element and is suitable for global scaling; 3.vw/vh is based on the viewport size, suitable for responsive design, but attention should be paid to the performance under extreme screens; 4. When choosing, it should be determined based on whether responsive adjustments, element hierarchy relationships and viewport dependence. Reasonable use can improve layout flexibility and maintenance.

What are common CSS browser inconsistencies? What are common CSS browser inconsistencies? Jul 26, 2025 am 07:04 AM

Different browsers have differences in CSS parsing, resulting in inconsistent display effects, mainly including the default style difference, box model calculation method, Flexbox and Grid layout support level, and inconsistent behavior of certain CSS attributes. 1. The default style processing is inconsistent. The solution is to use CSSReset or Normalize.css to unify the initial style; 2. The box model calculation method of the old version of IE is different. It is recommended to use box-sizing:border-box in a unified manner; 3. Flexbox and Grid perform differently in edge cases or in old versions. More tests and use Autoprefixer; 4. Some CSS attribute behaviors are inconsistent. CanIuse must be consulted and downgraded.

See all articles