How to make a slick CSS animation from Upload
This time, I will tackle a title sequence from Upload.
Upload is an American science fiction comedy-drama television series created by Greg Daniels. The story takes place in 2033, when humans can “upload” themselves into a virtual afterlife of their choosing. When a programmer Nathan Brown dies prematurely, he is uploaded to the luxury Lakeview facility, but then finds himself under the thumb of his possessive, still-living girlfriend Ingrid who has paid for him to be there.
It is quite a funny series, and is geek adjacent. It is worth checking out!
The title sequence
Below is a clip of the title sequence from episode 2 of season 1, which we will be making.
The title sequence mimicks an upload progress bar, slowly revealing the name of the TV series as it goes. The text is transparent and underneath it shows an image, which is the first frame of the opening scene. People usually refer to this as “knockout text”, that is text that appears cut out, such that you can see a background behind it.
Just before the name is fully revealed, it glitches, and then flies past the viewer to reveal the opening scene.
TLDR
Here is the codepen with the final result.
Give it a ❤️ on Codepen if you like it! 😊
Design considerations
After searching a bit, I found that Paytone One was a good match for the font of the title text. It is available on Google Fonts.
The central part of the animation is the knockout text. There are a number of ways you can achieve this effect and it would be great to do it in CSS entirely, but there are some catches:
- The knockout text moves towards the viewer while the background remains static. This rules out techniques that apply the background image to the actual text, such as using
-webkit-background-clip: text;
. - The glitch effect has colourful elements between the background image and the text. In order to do this in the least complex manner, it is preferable to have the background image as a separate element to the knockout text, and be able to place whatever we want between them. We could use a
clipPath
that contains a duplicate of ourtext
element, and apply it to the glitch elements. This ensures that there will be no overflow. However, we may need to apply the animation that moves the text towards the viewer to theclipPath
to keep things in sync, even though the glitch is quite brief (300 milliseconds or so). It would be more performant if we don’t move the glitching elements at all, and just animate their appearance.
With this in mind, I think it would be easier to bake in the “knockout text” inside a vector graphics editor. I can turn the text
element into a SVG path
and combine it with a black rectangle to create a single path
.
Here is a visual overview of what we want to create:
Making the SVG
We will create the SVG by hand initially. We want a landscape SVG, so we can create this with a viewBox
that specifies the width as 1200 units, and height as 800 units. We want a black rectangle that will fill the entire canvas, so we give it a width of 1200 and height of 800.
We will add a text
element and position it towards the center of the canvas, so we can see it! We specify our font via the font-family
attribute. We will pick a big font-size
to begin with to see how it looks, and give it a fill
of white, so that we can see it against the black rectangle.
Now, we can open this up in Inkscape (or your favourite vector graphics editor). If you are using Inkscape, I recommend installing the SVGO plugin for Inkscape. This will enable you to optimize the markup when you save the file.
I will guide you through creating the SVG in Inkscape.
First thing that I check is the document properties. On the menu, go to File, then Document Properties…. It opens up the following tab.
It appears the canvas dimensions are a bit small, it is 300px by 150px. Let’s change that to 1200px by 800px to match our viewBox
.
Now, let’s look to size and align the text now. First, we can try some bigger font sizes by clicking on the text tool (press the letter T to activate it). Let’s double the size to 200px.
Now, let’s open the Align and Distribute tab so we can center our text. On the menu, click on Object, then select Align and Distribute… . It opens this tab.
Click on the “UPLOAD” text
element. We want to align our text element relative to the page, and center on both axes:
- Check it that “Page” is selected in the dropdown box
- In the Align section, click the “Align on vertical axis” button. This is the third button on the first row, as circled in green in the screenshot below.
- Now, click the “Align on horizontal” button. This is the third button on the second row, as circled in green in the screenshot below.
And this is the result:
The letter spacing is a bit tighter in the title, so lets adjust our text to match it. I tried some values and minus 10 was the sweet spot, as below.
As the text is a bit narrower now, lets center it again. Repeat as I described previously.
Stroked text
We want to duplicate the text
element to use as it the stroked outline. So we can see what we are doing, create a rectangle off to the side of the canvas and fill it in red. Now, select and copy the text element, and paste it on top of the red rectangle. Now select the duplicate, and let’s style it. Go the to menu, click on Object, then select Fill and Stroke… to open the Fill and Stroke tab.
Now, select clear the fill. We select the red X on the Fill sub-tab. Next, go to the Stroke paint tab and pick white. Finally, move to the Stroke style sub-tab and select 4px as the stroke width.
Knocking out the text
We want to convert our elements to paths in order to integrate them as a single path
element. Select the black rectangle and white text element. On the main menu, click on Path, and select Object to Path. Now the recentangle is a path
, and the text
element has become a group with 6 path
elements, one path
for each letter.
Our next move does not work if the letters are inside a group. Select the group and right-click, select Ungroup from the context menu. Now select the rectangle path and the 6 letter paths. It should look like this.
Notice the separate dashed lines around each path
!
We can now combine all the paths in the way we want. On the main menu, click on Path, then select Exclusion. Now the text has been knocked out of the rectangle.
To prove it worked, you can drag it over the red rectangle to see how it is a single object with the negative space in place of the text.
Combining and aligning
The last bit is to position the “stroked text” text
element exactly on top of the knocked out text. You can see how this looks below.
Instead of the red rectangle, we will be able to have an image underneath that will peer through the negative space!
Now, you can delete the red rectangle!
The elements required for revealing the text
I will do this bit by hand.
This what the SVG looks like so far.
Later, we will be manipulating the path
and text
together, so lets group them for convenience. I will wrap them in a g
element, and give it an id
of “title”.
We will add a black rectangle to cover everything, and animate this later to reveal the text. Let’s call this our “reveal” rectangle. It will have the same dimensions as the canvas.
We create a second small rectangle for the white beam that tracks the progress for the revealing of the title. We wil make it thin, a width of 10, and the height can be the same height as the canvas. We give it a x
coordinate of minus 10, and a y
coordinate of zero. This is so it to the left of the “reveal” rectangle. We will give it a fill of white for now, we can tweak this later to look a bit better.
We will position the “beam” rectangle underneath (before) our “title” group.
Putting it all together the SVG looks like this:
At this stage, I prefer to try out animating what I have. I get a bit impatient to get going! You can continue on and create the glitch elements if you prefer.
Glitch elements
From the outset a glitch effect can seem complicated, but it can be quite simple. In this case, the glitch effect happens very quickly, so it can be quite rudimentary and rough.
The best starting point for us is to grab a screenshot from the actual title sequence. Below you can see the glitch is just some coloured rectangles positioned randomly in bands. We can just replicate this.
Open the SVG from the last step, and move the “reveal” rectangle to the side. Let’s just draw the colored rectangles similar to the reference above. This is what I did.
Select the coloured rectangles you made and group them together. Now, place this group underneath the “title” group.
Next, we want to turn this group into a symbol
, so that we can reuse it in multiple places. You can do this inside Inkscape, but I find it a bit awkard. I find it easiest to do is to open the SVG source and make the edits myself. Later, we will experiment with using multiple instances of the glitch, we will shift these instances around quickly to give the impression of shifting pixels. We will add 3 instances for now, slightly offset from each other and see how we will get on with it later.
We create a defs
, and we wrap our rectangles inside a symbol
, which we place inside.
Then directly underneath, before the “beam” rectangle, we add 3 use
instances:
When we get into this territory with manual editing, Inkscape no longer can show our SVG! I opened it in Firefox to see how it looks:
To complete the SVG for now, we restore the “reveal” rectangle to its initial position. We also add opacity="0"
to all 3 use
instances to hide them until we will animate them. You can see the SVG below to see the markup.
That is the hard part done. My methods are probably a bit unorthodox here, so don’t worry if some of it seems a bit strange! All editors have their limitations when converting drawn graphics to SVG elements, editors can output some gnarly markup. I don’t know if you should follow my habits, ideally you would do all of the drawing and arranging in the graphics editor!
We may need to make some tweaks later when we animate it. I suspect that I may need to convert the text
element to a path
as this can be a pain point in some browsers. Let’s get stuck in!
Basic HTML and CSS
Before we get to the animation, we need to write our HTML, and add some basic styles.
The HTML
We wrap the SVG we made in a “container” div
. It is this div
that we will add our background image to.
The CSS
We add some dimensions to our container, and center it with margin: 0 auto
. We add the background image to the container and have it cover it completely.
We want our SVG to span the full width of the container as an overlay.
Load the font somewhere
You can load the font by:
- Adding the resources to the
head
to load it from Google Fonts/locally. - Adding
@import
statement to the CSS file. - Declare it as a
@font-face
rule.
I prefer to bypass Google Fonts, so I load it locally. And I choose option 3 when I do this as my own local experiment.
Font loading strategies is a meaty topic of its own, that I will not get into now! The key takeaway is to have the browser load the font quickly, we don’t want the browser to swap out the fonts in an ugly way.
Animation time
I wil break the animation into 4 parts:
- Bringing the title towards the viewer that culminates in the title moving beyond the viewer, leaving the picture revealed underneath
- The slow reveal of the title in a chugging fashion that mimicks an uploading bar
- The leading beam that tracks the reveal of the title
- The glitch effect
Part 1: Bringing the title towards the viewer
It is generally a good idea to start with this part of the animation because it can impact the rest of the animation the most. Performing transformations on text has its pitfalls.
You can achieve the same effect with transform: scale()
or transform: translateZ()
. I find the results are generally better with scale()
. Chrome is particularly fussy when you do transformations on text. One reason for this is that Chrome treats 3D transformed elements as textures instead of vectors in order to provide hardware 3D acceleration. This can make text appear blurry when you move it around in 3 dimensions.
I have done it both ways below, so you can see the results side-by-side.
I tested them and they both look the same in Firefox. However, I found that the translateZ()
version behaves in a peciular way on Chrome, especially on mobile!
With translateZ()
You can find the right value to supply to perspective to give the right “viewing distance”. For the majority of the time, we are slowly moving the title positively along the Z axis (towards the viewer).
We want it to move very fast at the end, so we pick a big value for translateZ()
so it whizzes beyond the viewer.
This is what the code (codepen) looks on Chrome (Linux and Android) 😵💫:
I did try some variations out by using transform-style
and perspective
, but it looked the same regardless.
With scale()
Similiar to the previous example, we are slowly increasing the size of the text for the majority of the time, until 90%. For the final 10%, we want to provide a big value to scale()
so that it outgrows the screen!
We also set the opacity to zero because we need to make it disappear. Otherwise we get stuck in the blackness of the center of the letter ‘O’! Also, I added translateX()
to the final transformation to move it to the right as it grows expotentialy to match the original.
This is it:
I’m still not totally happy with how it looks in Chrome, there is a slight bit of jank, it appears that the text is vibrating.
I can convert the text
element to a group of path
elements and see if it will improve it!
This is what it becomes:
Notice that we have an aria-label
so that the text is still accessible!
And it appears to be smoother.
We will use this version!
Part 2: The slow reveal of the title
The reveal animation requires moving our rectangle, which has the id
of “reveal”, across the SVG canvas in chugging way. It reveals the beginning of the word quickly, but stops approxmiately one third of the way in (over the letter ‘P’) and slowly moves across the letter. This behaviour repeats twice. It jumps quickly to two thirds of the way in (over the letter ‘O’) and slowly reveals the final part of the letter. Lastly this repeats for the final letter ‘D’.
We will use a translateX()
transformation with positive values. There is no secret sauce here, we just got to experiment to find the right input values for the animation. I find percentages are easiest to work with.
Roughly 33%, 66%, 90% are good starting inputs to translateX()
for the slow movement sections. For the distance covered for the slow movement, let’s say it moves 5% more.
The jump to these points is very quick, so in terms of time, we want a small amount dedicated to the intervening jumps, let’s start with 2%.
The first cut would be something like this for the first 2 jumps:
- From 0% to 2% of the timeline, move right 33% in total.
- From 3% to 30% of the timeline, move right 38% in total.
- From 31% to 33% of the timeline, move right 50% in total.
- From 33% to 60% of the timeline, move right 55% in total.
Then, it is a matter of tweaking these values until you are happy. Here are the magic numbers:
And here we are:
Part 3: The leading beam that tracks the reveal of the title
Since the movement of the beam follow the “reveal” rectangle, I just copied the “upload” @keyframes
and renamed it to “follow-reveal”. The only thing that requires a change is the initial jumping phase - I wanted the beam to be invisible. So I added scale(0)
to the transformation to shrink it to nothing, and then scale(1)
to restore it to regular size when it should be seen. We can get away without hiding the beam in the 2 subsequent jumps since it happens so quickly.
This is a case where I went back to tweak the SVG to give the beam a more transulent, blurry appearance. I open up an earlier version of the SVG that Inkscape would display and change the fill
. Instead of a solid white, I give it a right-to-left linear gradient with white and grey. Then I added a blur filter, via the menu (Filters > Blurs > Blur…). Hopefully, this will not have no negative impact on the animation speed, adding blur to anything makes me nervous!
Here is a video showing a side-by-side comparison, the tweaked version is on the left, and the original version is on the right. Try pausing it at a couple of junctures to see the difference.
It looks marginally better IMHO.
Part 4: The glitching
Taking another glance at the reference shot of the glitch, you will notice that the background image is actually desaturated in this moment also.
This is a 2-step affair. Since our glitch happens 3 seconds into the sequence, we will need to delay it. Let’s add a CSS variable for this as we will need to use this value in a couple of places.
I tried some values out with the grayscale()
and saturate()
CSS filter functions, and found grayscale()
to look the best. We will have it happen 200 milliseconds before our colourful boxes step.
For showing our colourful boxes with the class “glitches”, we will stagger them animating. We will give them each a different animation-delay
to achieve this. For the animation, we will move them around a bit (mostly down), and play with the opacity so it appears subtly.
What I found is that it looks best to appear at 75% opacity in the beginning, and then move it across and down, then fade it out completely.
It turned out to be too subtle. I added 2 more instances of the “glitch” symbol to bring the total to 5 instances. I tried out different positions and found it to be a stronger showing overall.
You can see the final outcome in the completed animation.
Completed animation
Source code
The source code is available in this github repo. I will create more title sequences soon and add them to the repo also.
Also, you can check them all out in this codepen collection.
Wrapping up
If you made this far, I salute you! 👏