Open In App

How to Create Typewriter Animation using HTML and CSS ?

Typewriter animation as the name suggests is an effect that looks like a typing animation, as being typed by a typewriter. We are going to create this animation without JavaScript and just using HTML and CSS.

Approach: To achieve the typewriter effect we will use the following CSS properties.



Example: In this example, we will be going to use the above-defined properties to create typewriter animation.




<!DOCTYPE html>
<html>
<head>
    <title>Typewriter Effect</title>
 
    <style type="text/css">
        {
            box-sizing: border-box;
            padding: 0;
            margin: 0;
            outline: none;
        }
 
        body {
            background-color: #2ca32c;
            justify-content: center;
            align-items: center;
            height: 100vh;
            display: flex;
        }
 
        h1 {
            font-size: 90px;
            white-space: nowrap;
            overflow: hidden;
            animation: typewriter 2s steps(13) infinite alternate,
                blink 800ms steps(13) infinite normal;
            border-right: 5px solid black;
        }
 
        @keyframes typewriter {
            from {
                width: 0%;
            }
 
            to {
                width: 50%;
            }
        }
 
        @keyframes blink {
            from {
                border-color: black;
            }
 
            to {
                border-color: transparent;
            }
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
</body>
</html>

Output:



Note: For other longer or shorter text, required changes should be done in font size, steps. The time of the animation of text and the cursor should also be changed accordingly.


Article Tags :