<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Valentyn Vasylenko on Medium]]></title>
        <description><![CDATA[Stories by Valentyn Vasylenko on Medium]]></description>
        <link>https://medium.com/@valentyn.vasylenko?source=rss-bd16c0680fd5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7T_b9tBIAtZh-UnVB78bcA.png</url>
            <title>Stories by Valentyn Vasylenko on Medium</title>
            <link>https://medium.com/@valentyn.vasylenko?source=rss-bd16c0680fd5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 19:57:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@valentyn.vasylenko/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Typewriter Effect with Alternating Text in Pure CSS3]]></title>
            <link>https://medium.com/@valentyn.vasylenko/typewriter-effect-with-alternating-text-in-pure-css3-72cf0c7e6c5?source=rss-bd16c0680fd5------2</link>
            <guid isPermaLink="false">https://medium.com/p/72cf0c7e6c5</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css-animation]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css3]]></category>
            <dc:creator><![CDATA[Valentyn Vasylenko]]></dc:creator>
            <pubDate>Mon, 05 Nov 2018 03:47:15 GMT</pubDate>
            <atom:updated>2018-11-05T17:54:55.324Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*6Z_LOHZlyyBlawGz5fgbdw.gif" /><figcaption>Check out this amazing animation live — <a href="https://hackeryou.com/">https://hackeryou.com/</a></figcaption></figure><p>If you are looking for ways to make your static page feel more “alive” with pure CSS3 — you are in the right place! Typing animation, better known as a “Typewriter” effect, is one of those cheap tricks that are very easy to implement but never fail to impress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*L9j9k-j-IK73QrtVFEEgoQ.png" /></figure><p>The effect that you see on <a href="https://hackeryou.com/">HackerYou’s</a> website can be easily accomplished with JavaScript, but let’s see if we can replicate it using just CSS and a cup of coffee.</p><h3><strong>Step 1 — Animation without alternating text</strong></h3><p>Let’s start with the basics and create our HTML first. We will need a <strong>H1</strong> tag and a <strong>span</strong> with our text inside, let’s give it a class name of <strong>text_1</strong>.</p><pre>&lt;h1&gt;&lt;span class=&quot;text_1&quot;&gt;I&#39;m a dynamic heading&lt;/span&gt;&lt;/h1&gt;</pre><p>Now we’re going to give our <strong>span</strong> some setup styles that will allow our animation to work properly. First of all, since all spans are <strong>inline</strong> elements by default, we’ll need to set it’s display property to <strong>inline-block </strong>in order for it to accept<strong> width</strong>. Also we have to make sure our text doesn’t jump to the next line and hides overflow when being resized.</p><pre>.text_1 {<br>  overflow: hidden;<br>  white-space: nowrap;<br>  display: inline-block;<br>  position: relative;<br>}</pre><p>You know what would go great with our boring text? A caret! Let’s make one using an <strong>after</strong> pseudo-element and make sure it’s stuck next to our text at all times.</p><pre>.text_1::after {<br>  content: &quot;|&quot;;<br>  position: absolute;<br>  right: 0;<br>}</pre><p>It’s time to create some animations. We want our caret to blink once every second and our text to resize from <strong>0</strong> to its <strong>original</strong> <strong>width</strong> and back. Here comes the first problem. If we set our text to <strong>width: 100%</strong> it will take the full width of the page. Our goal is to make sure it never goes beyond its original width, otherwise it will continue animating empty space that comes after your letters.</p><p>That’s why instead of percentages we’re going to be using <strong>em</strong>s. How many <strong>em</strong>s will you need for your text? Hard to say, you’ll have to adjust it by hand. My rule of thumb is to take the number of letters and spaces in your sentence and divide it by 2. You will still have to play with the result a little bit, but it’s going to be very close.</p><pre><a href="http://twitter.com/keyframes">@keyframes</a> typewriter {<br>  0%, 100% {<br>    width: 0;<br>  }<br>  20%, 80% {<br>    width: 10.2em;<br>  }<br>}</pre><pre><a href="http://twitter.com/keyframes">@keyframes</a> caret {<br>  0%, 100% {<br>    opacity: 0;<br>  }<br>  50% {<br>    opacity: 1;<br>  }<br>}</pre><p>Almost done, now let’s add them to our elements. We’re going to be using <strong>steps()</strong> as our <strong>animation-timing-function</strong> to replicate the jittery transition from letter to letter as they are being typed. Plus we’re going to set our caret’s number of steps to 1 to completely eliminate any intermediate animations between opacity 1 and 0.</p><pre>.text_1 {<br>  overflow: hidden;<br>  white-space: nowrap;<br>  animation: typewriter;<br>  display: inline-block;<br>  position: relative;<br>  animation-duration: 10s;<br>  animation-timing-function: steps(25, end);<br>  animation-iteration-count: infinite;<br>}</pre><pre>.text_1::after {<br>  content: &quot;|&quot;;<br>  position: absolute;<br>  right: 0;<br>  animation: caret infinite;<br>  animation-duration: 1s;<br>  animation-timing-function: steps(1, end);<br>}</pre><h4>Result:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fvasylenkoval%2Fembed%2Fpreview%2FJeoWdg%3Fheight%3D600%26slug-hash%3DJeoWdg%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fvasylenkoval%2Fpen%2FJeoWdg&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F2549010.JeoWdg.small.2667dff0-480b-4e6c-bdbd-6b70778b7b84.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b56942ebfb70269bfbe60bb02a47d5d/href">https://medium.com/media/3b56942ebfb70269bfbe60bb02a47d5d/href</a></iframe><h3>Step 2 — Animation with alternating text</h3><p>It’s time to supercharge our typewriter. Let’s add one more <strong>span</strong> inside our <strong>H1</strong> and give it a class of <strong>text_2.</strong></p><pre>&lt;h1&gt;<br>&lt;span class=&quot;text_1&quot;&gt;Fancy heading on your static web page&lt;/span&gt;&lt;span class=&quot;text_2&quot;&gt;What?? How does it change without javascript?&lt;/span&gt;<br>&lt;/h1&gt;</pre><p>Since we agreed not to use JavaScript for this, we’ll have to figure out a way to alternate between our spans with animations only. The approach we’re going to take in this tutorial will be to make keyframes that run at the same time, but are a mirrored reflection of each other.</p><p>It means that while “stuff” is going to be happening in one keyframe, the other one should not change and vice-versa.</p><pre><a href="http://twitter.com/keyframes">@keyframes</a> text2 {<br>  0%, 50%, 100% {<br>    width: 0;<br>  }<br>  <br>  60%, 90% {<br>    width: 21.2em;<br>  }<br>}</pre><pre><a href="http://twitter.com/keyframes">@keyframes</a> text1 {<br>  0%, 50%, 100% {<br>    width: 0;<br>  }<br>  10%, 40% {<br>    width: 17em;<br>  }<br>}</pre><p>Do not forget to change your em values according to the number of letters in your sentences!</p><p>Lastly, we’ll apply this animation on our spans and see the final result.</p><pre>.text_1 {<br>  animation: text1;<br>}</pre><pre>.text_2 {<br>  animation: text2;<br>}</pre><pre>.text_1, .text_2 {<br>  overflow: hidden;<br>  white-space: nowrap;<br>  display: inline-block;<br>  position: relative;<br>  animation-duration: 20s;<br>  animation-timing-function: steps(25, end);<br>  animation-iteration-count: infinite;<br>}</pre><pre>.text_1::after, .text_2::after {<br>  content: &quot;|&quot;;<br>  position: absolute;<br>  right: 0;<br>  animation: caret infinite;<br>  animation-duration: 1s;<br>  animation-timing-function: steps(1, end);<br>}</pre><h3>Final Result</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fvasylenkoval%2Fembed%2Fpreview%2FPxoVXr%3Fheight%3D600%26slug-hash%3DPxoVXr%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fvasylenkoval%2Fpen%2FPxoVXr&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F2549010.PxoVXr.small.65eee48a-db04-4b8b-a74a-127c1758d028.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb186c57b76b89bf06e039724a6a5e40/href">https://medium.com/media/fb186c57b76b89bf06e039724a6a5e40/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72cf0c7e6c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>