Blog

Animating with Style: CSS Animation Dos, Don’ts, and Starting Points

Bild mit 3 Personen am Laptop, E-Commerce Valantic CX

When wielded with skill, animation can breathe life into a website. However, as with any craft, there’s a fine line between enchantment and distraction.

In this article, I’ll cut through the complexity and give you the straightforward dos and don’ts of animation, plus the perfect starting points to ensure that your web elements dance to the rhythm of user engagement, not user frustration, all while keeping your website performing as it should. Let’s get to it!

Choosing Your Moves: Understanding Types of UI Animation and Their Purposes

When it comes to UI animation, every movement serves a unique purpose and, when used appropriately, can enhance the user experience in subtle yet significant ways. Let’s break down the most common types of UI animation and discuss what they’re best used for.

1. Transitions

Transitions help users understand the flow of their actions within the interface by smoothly changing from one state to another. Use transitions for hover effects on buttons and links, revealing dropdown menus, and expanding and collapsing accordions.

This accordion animation created by Elliot Nolten conveys a sense of natural flow in the way the accordion items expand and collapse.
This accordion animation created by Elliot Nolten conveys a sense of natural flow in the way the accordion items expand and collapse.

2. Microinteractions

Microinteractions are small animations that occur as a result of user actions. They answer the question “What just happened?”, providing immediate feedback and can guide users through tasks, making the experience intuitive and rewarding. Microinteractions are great for form validation feedback, toggle switches and loading indicators.

In the example above, it is easy to see the value of microinteractions in informing the user what button was clicked. Credited to Yellow.Y.

3. Entrance and Exit Animations

These animations control how elements appear and disappear from the screen, which can draw attention to important information or remove distractions. Entrance and exit animations can be employed on pop-ups, notifications and adding or removing items from a list.

In the above example, you can see how adding simple entry and exit animations can add character to any list. Credited to Dribbble.
In the above example, you can see how adding simple entry and exit animations can add character to any list. Credited to Dribbble.

4. Attention-Seekers

Sometimes you need to draw a user’s attention to a specific part of the screen, such as an error message or a call-to-action button. These animations should be used only when necessary to avoid overwhelming the user needlessly. Some situations that can benefit from this are error messages, promotional banners and feature highlights.

5. Progress Animations

When a task takes time to complete, progress animations keep users informed about what’s happening behind the scenes, reducing perceived wait times and preventing frustration. Some examples of where progress animations can be useful are loading bars, progress circles and the sequential loading of content.

This Waiting Finger-Tapping preloading animation made by DΞNYS SΞRGUSHKIN is a fun and light-hearted way to keep users engaged while waiting.
This Waiting Finger-Tapping preloading animation made by DΞNYS SΞRGUSHKIN is a fun and light-hearted way to keep users engaged while waiting.

6. Narrative Animations

Narrative animations tell a story and are often found in onboarding experiences or as a part of a website’s storytelling element. They should be used to create memorable experiences that immediately convey the essence of a brand by guiding users through a visual journey from the moment they arrive.

The narrative animations in the Singapore Airlines Boarding site not only provide a delightful exploration experience but also serve as a clever way to keep users excited while imparting important information.
The narrative animations in the Singapore Airlines Boarding site not only provide a delightful exploration experience but also serve as a clever way to keep users excited while imparting important information.

By understanding the types of UI animations and their intended uses, you can create a more cohesive and functional user interface. Remember, the goal of animation should always be to enhance the user experience, not detract from it. So what should we aim to avoid when designing our experiences?

Steering Clear of Pitfalls: Performance, User Experience, and Accessibility in CSS Animation

When it comes to sprucing up your website with CSS animations, it’s essential to balance aesthetic flair with performance. After all, what good is a stunning visual effect if it leads to a sluggish and jarring user experience? Let’s delve into some key performance considerations to ensure your animations are as efficient as they are impressive.

1. Prioritize Performant Properties

The golden rule of performant CSS animations is to animate properties that are less taxing on the browser. Transform and opacity are your go-to properties because they can be handled by the browser’s composite layer, which means less work for the main thread and smoother animations.
Confused? Let’s take a quick look at how the rendering pipeline works.

The Rendering Pipeline
The Rendering Pipeline

When a browser paints your webpage, it follows a specific sequence. It starts by applying styles, then calculates the layout (where elements sit on the page), followed by the paint (filling in the pixels), and finally, it reaches the compositing stage. During compositing, the browser layers everything together in the right order.

To keep animations performant, we should aim to involve just the compositing stage. This is why animating using transform and opacity is akin to taking the express lane in the rendering pipeline—they mostly skip straight to compositing.

When in doubt about how a particular CSS property will affect your animation’s performance, there’s a handy tool at your disposal: CSS Triggers. This website provides a comprehensive look at how different CSS properties impact the rendering pipeline, so you can make informed decisions and keep your animations running smoothly.

2. Mindful Motion: Respecting User Preferences

One of the cornerstones of accessible animations is acknowledging and respecting the preferences of users who are sensitive to motion. The prefers-reduced-motion media query is a powerful tool in our CSS arsenal that allows us to detect if a user has requested reduced motion in their system settings. When this preference is indicated, we should ensure that animations are either toned down or replaced with a non-animated alternative.

3. Clear Path: Keeping Animations Distraction-Free

Animations should enhance the user experience, not detract from it. We must ensure that animations do not distract from critical information or make the content hard to read. It is possible to have too much of a good thing, and mistakes such as animations taking too long or being too confusing can detract from user engagement and be a nuisance rather than visually pleasing.

This useful comparison by Taras Skytskyi makes it easy to see the fine line between awesome and annoying.
This useful comparison by Taras Skytskyi makes it easy to see the fine line between awesome and annoying.

Furthermore, from an accessibility strandpoint, it’s important to avoid animations that flash or flicker, as these can cause discomfort or even seizures in individuals with photosensitive epilepsy. Let’s try to keep our interfaces as safe as possible so that they can be enjoyed by everyone!

4. Pause, Stop, Hide: Giving Control to the User

On that note, providing mechanisms to pause, stop, or hide animations empowers users to control their experience on your site. This can be an absolute game changer for users who find continuous motion unsettling or distracting. Consider implementing buttons or settings that allow users to adjust the level of animation they encounter.

This GIF by Oriana García is a clear demonstration of the difference that the power of choice can make.
This GIF by Oriana García is a clear demonstration of the difference that the power of choice can make.

In Conclusion: Go Forth and Animate!

As we wrap up our journey through the art of CSS animations, it’s clear that they are a powerful tool in the web designer’s palette. They can guide, inform, and delight users, contributing to a dynamic and interactive experience. But with great power comes great responsibility. The dos and don’ts we’ve discussed serve as a roadmap to creating animations that are not only visually appealing but also performant, accessible, and user-friendly.

From understanding the different types of animations and their appropriate uses to navigating the potential pitfalls that can impact performance and accessibility, we’ve covered the essentials that every web designer and developer should consider. Remember to prioritize properties like transform and opacity for smoother animations, respect users’ motion preferences with prefers-reduced-motion, and provide control mechanisms for animations to ensure a comfortable experience for all users.

By keeping these principles in mind, you’re now equipped to go forth and animate with confidence. Your web elements can truly dance to the rhythm of user engagement, creating memorable experiences without sacrificing performance or accessibility. So, take these insights, apply them to your work, and watch as your websites come to life in the most inclusive way possible. Happy animating!

Bild von drei Kolleg*innen, die sich zusammen in der Kaffeepause etwas auf einem Smartphone ansehen.

Talk to our experts!

Contact Contact

Don't miss a thing.
Subscribe to our latest blog articles.

Register