new course
CSS grid landing page tutorial (36min)

Lesson info

Lesson info

Transitions help you create smooth animations between different states of an element, using duration and easing types. They're very handy in keeping changes in state from looking and feeling abrupt and jarring. 

In this video, we'll show you how to add transitions between elements and customize your transition values to achieve just the result you're looking for.

Clone this projectDownload project assetsDownload lesson assets

Transcript

As opposed to abruptly cutting between two different states, we can add transitions which animate these values over a set duration.

Here are some thumbnails. They're for blog content. If hover over them now, nothing happens. Actually, that's not true. We get our normal element blue highlighting effect. But, we can turn that off right over here.

But we can see that hovering does virtually nothing. That's because we haven't made any changes to our states. Let's select one of these and go over to States, and then Hover. For right now, we'll make a change to the background color.

If we hover? The background color change behaves as expected, but it cuts abruptly. If we go into States and switch back to None? We can scroll down and add a transition. In the dropdown, of course, we'll select Background Color. And with the default duration, 200 milliseconds, it fades smoothly. We can also change this number. Let's do 500 milliseconds. Hover again? And the transition takes place over 500 milliseconds.

We can also go in and change the curve type — the easing curve — from the Easing Editor.

Let's move forward with another example. This time let's do the same thing with font color. We'll go to States and then to Hover, and we'll change our font color to get it just right. As expected, we have an abrupt cut on hover. Let's go back over to our None state (which is odd, because it's not really a state like hover or Wyoming). From None, we can go down and add a transition. This time, we'll select from our dropdown: Font Color. Let's switch to 2,000 milliseconds (or two seconds). And on hover, we have a smooth albeit kind of slow transition.

Finally, let's play with shadows.

Over here, we can add a subtle shadow. We can go in and make changes to these values so everything looks just how we want it to look before we cover the hover and transition. And when we're done? Let's go over to our Hover state. If we increase the intensity of our shadow? Or even the distance? That hover cut — that abrupt transition (or lack of transition) is obvious. By now, you probably know what we're going to do.

Now we can see here that the transition area is grayed out. Why? Because we're styling in the Hover state. And as we know, we have to switch back to None to add a transition. And when we do? We can add a transition. This time we'll select Box Shadow from our dropdown. And we'll switch to 500 milliseconds.

If we demo that, we can see the shadow intensity — and its distance — transition smoothly.

There's so much more you can do with transitions. Keep in mind: it'll transition style changes between Hover and Pressed as well — using those same transition values.

But that's how to add and configure transitions between a class's states.