The animation will run on page load, to run it again click the small button “Rerun” on the bottom right.
How does it work?
To achieve such an effect we are going to rely on the background property and more precisely gradient layers. We are not going to clutter our code with a lot of <div> or pseudo-elements. Only two background layers will do the trick.
We will have one layer that will color the text and another one will come on top of the text. Then we will adjust the size/position of each layer to create the animation.
The HTML code will look like the below:
<span class="reveal">The text to reveal</span>
It’s important to notice that we need to consider an inline element as a container for the text. If you want to apply the effect to a title, for example, don’t do
<h1 class="reveal">The text to reveal</h1>
But instead, you have to write
<h1><span class="reveal">The text to reveal</span></h1>
The use of an inline element is the trick to make the effect works on multi-line of text.
Now that we have a clear idea of how it does work, let’s write some CSS.