Skip to content

Instantly share code, notes, and snippets.

@jlord
Last active December 15, 2015 03:09
Show Gist options
  • Save jlord/5192831 to your computer and use it in GitHub Desktop.
Save jlord/5192831 to your computer and use it in GitHub Desktop.
CSS Typing Animation

CSS Typing Animation

A CSS typing animation, inpsired by Lea's, but the "cursor" is relative to the type so that you aren't limited to just monospace typeface, and this does not require background/span color matching so are free to use any background you want.

Here is the codepen.

woo!

@jllord

<html>
<head>
<title>Typing, Ma!</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- outside of breif gists I'd use lettering.js to do line 9 for me -->
<h1>
<span class="char1">H</span><span class="char2">i</span><span class="char3">.</span>
</h1>
</body>
</html>
body {font-family: Helvetica; background: #efefef;}
h1 {font-size: 100px; color: #333;}
/* you start with transparent type and faux cursor */
/* each character has typing animation for .5s */
/* fill mode makes the text keep the color it gets in animation */
.char1, .char2, .char3 {
color: transparent;
border-right: .1em solid transparent;
-webkit-animation: typing .5s;
-webkit-animation-fill-mode: forwards;
-moz-animation: typing .5s;
-moz-animation-fill-mode: forwards;
}
.char1 {-webkit-animation-delay: .5s;}
.char2 {-webkit-animation-delay: 1s;}
/* give your last character some padding and the blink animation */
.char3 {
padding-right: 2px;
-webkit-animation: typing 1s;
-webkit-animation: blink 1s infinite;
-webkit-animation-delay: 1.5s;
-moz-animation: typing 1s infinite;
-moz-animation: blink 1s infinite;
-moz-animation-delay: 1.5s;
}
/* typing animation */
@-webkit-keyframes typing {
from, to {color: #333; border-color: transparent; }
70% {color: #333; border-color: #07D6FF; }
}
@-moz-keyframes typing {
from, to {color: #333; border-color: transparent; }
70% {color: #333; border-color: #07D6FF; }
}
/* the blinking faux cursor at the end */
@-webkit-keyframes blink {
from, to {color: #333; border-color: transparent;}
50% {border-color: #07D6FF;}
}
@-moz-keyframes blink {
from, to {border-color: transparent;}
50% {border-color: #07D6FF;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment