Simple typing CSS animation
by anoopsuda
HTML
<div class="css-typing">
<p>
Typed text 1
</p>
<p>
Typed text 2 Longer
</p>
<p>
Typed text 3
</p>
</div>
CSS
.css-typing p {
border-right: .15em solid orange;
font-family: "Courier";
font-size: 14px;
white-space: nowrap;
overflow: hidden;
}
.css-typing p:nth-child(1) {
width: 7.3em;
-webkit-animation: type 2s steps(40, end);
animation: type 2s steps(40, end);
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.css-typing p:nth-child(2) {
width: 11.5em;
opacity: 0;
-webkit-animation: type2 2s steps(40, end);
animation: type2 2s steps(40, end);
-webkit-animation-delay: 2s;
animation-delay: 2s;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
}
.css-typing p:nth-child(3) {
width: 7.3em;
opacity: 0;
/* blink only during typing (2s), then stop */
animation:
type3 2s steps(20, end) forwards,
blink .2s step-end 2s; /* runs only for 2 seconds */
animation-delay: 4s;
animation-fill-mode: forwards;
}
@keyframes type {
0% {
width: 0;
}
99.9% {
border-right: .15em solid #000;
}
100% {
border: none;
}
}
@keyframes type2 {
0% {
width: 0;
}
1% {
opacity: 1;
}
99.9% {
border-right: .15em solid #000;
}
100% {
opacity: 1;
border: none;
}
}
@keyframes type3 {
0% { width: 0; }
1% { opacity: 1; }
100% {
opacity: 1;
border: none; /* remove cursor after typing */
}
}
@keyframes blink {
50% { border-color: transparent; }
}