Our eyes and brain are wired to notice the slightest changes in visual elements. That’s why you can easily discern a subtle change in the shape, color, or size of an object while viewing a page online. Because of our natural tendency to notice slight changes, CSS transitions are quite useful for creating powerful Call-to-Actions (CTAs) and other features that require people to take a particular action on your app or website (micro interactions).
We will be explaining in this tutorial what CSS transitions are and how you can apply transition properties to animate objects. So if you are interested in learning how to animate visual components of your app or website, this beginner’s guide to CSS transitions & animations is for you.
What Are CSS Transitions?
Simply put, CSS transitions allow visual elements to make a gradual change rather than an abrupt one. For example, if an animator changes an element from white to red, the change is always instant. However, with CSS transitions, that variance occurs fluidly, over a time duration or interval. That way, the user has a superb experience.
CSS Transition Properties
There are four essential properties that govern CSS transitions. These properties control how changes for visual elements function and appear:
Transition Property
This property highlights the CSS property you want to transition.
Using the example below, you can see that the background property is the only one listed to transition over a duration of 3 seconds.
NOTE: You cannot apply CSS transitions to all properties. They can only occur for recognizable properties like color, border width, border color, border-spacing, font size, background color, etc.
Transition Duration
Transition duration refers to the timing of a transition, or how often you want a change to occur to a component. For instance, you could set a transition to occur every two seconds. You can even set changes to happen in fractions of a second.
Here’s a visual explainer:
If you have several property values you want to transition, you will need to set individual durations for each value and separate them with commas.
NOTE: The positioning of a property value must tally with its duration. That is, the first property identified within the transition property must match the first time specified in the transition duration. However, in the case of multiple values with just one transition duration, that would be the duration of all the property values.
Transition Timing
This property refers to the speed of a transition, or how quickly you want a change to occur.
It’s easy to get Transition duration and Transition timing mixed up, but here’s the difference:
- Transition duration: The time interval for a transition to occur
- Transition time: The speed at which that transition occurs.
Here’s a visual explainer:
It’s also possible for transition duration to have multiple timings or different speeds and as with transition duration, you must separate individual speeds by comma values.
We can further describe transition timing with some essential values:
Ease Out: Occurs when a transition starts off rapidly but slows down to a halt eventually.
Ease In: Is the opposite of ease out. It’s a transition that starts off slowly and becomes rapid with time.
Ease-in-out: The transition slows down, becomes rapid with time, and slows down to a halt eventually.
Transition Delay
Another feature of CSS transitions is the Transition Delay. This property allows you to delay a transition for an amount of time.
The delay is the amount of time a transition would stall before execution. Like the previous properties, commas are used to separate individual values.
Here’s a visual explainer:
Cleaning up Your CSS Code
Applying multiple and complex CSS transitions on your page can often leave you with messy code that slows down the performance of your website. According to a Google poll, 75% of users said that they would abandon a page if it took longer than 5 seconds to load. Having this little time to secure users’ engagement, you’ll want to keep only CSS rules that are essential.
Having a smaller, more streamlined CSS code is the key to a faster website and improved user engagement which can lead to more conversions. Moreover, a shorter code will require less maintenance. Unused CSS is a site I recommend to help you remove redundancy from your CSS code. All you need to do is paste your website link in a text field and it will automatically scan your whole website for CSS rules and remove all the unnecessary code.
Final Thoughts: A Beginner’s Guide to CSS Transitions & Animations
Armed with this information about CSS transitions, you should try them out on some visual components of your website or app. You can also combine multiple properties to create both simple and complex transition effects. Remember, practice makes perfect!
Need help? Our WordPress Development Service is a comprehensive solution for small, medium, and enterprise-level businesses. Call us at 602-633-4758 for a free consultation.