Whether it's enhancing a button, killing fourth dimension while a folio loads, or adding some extra flair to a landing folio, animation is an constructive way to hold attention and delight viewers on your website.

While there are several ways to add animated graphics to a web page, one of the easiest is using CSS animations, which require nothing more than than some HTML and CSS know-how to pull off.

Download Now: Free HTML & CSS Hacks

If you desire to add CSS animations to your piece of work, it can be helpful to look at some successful uses of CSS animations first before diving in. This extra bit of research can inspire your own projects and provide a sense of what you can reach with this powerful feature.

That's why we've compiled our favorite examples of CSS animation from CodePen — an online tool for creating and sharing lawmaking snippets in HTML and CSS — to help get the creative juices flowing.

But offset, a brief review of the topic at mitt...

How do CSS animations piece of work?

CSS animation is a feature of CSS that allows yous to animate a change in one or more style properties of an element, as well as control diverse aspects of the animation. Pure CSS animations require no boosted code (e.g. JavaScript) or media (eastward.g. GIFs) — everything is washed with HTML and CSS.

CSS animations are groovy for websites that desire to add dynamic, engaging content without placing much more weight on the page. Since they don't require extra scripts, CSS animations are unlikely to slow down your pages.

To make a CSS animation, yous need 3 things: an HTML chemical element to animate, a CSS rule which binds the animation to this element, and a group of keyframes that defines the styles at the get-go and end of the blitheness. You tin also add together declarations to farther customize your animation, like speed and delay.

To demonstrate, hither's a simple example of a CSS animation:

See the Pen CSS Animation Instance past Christina Perricone (@hubspot) on CodePen.

In this example, <div></div> is the element nosotros're animating. Looking at the CSS, we see that our animation declarations are associated with the div selector. The about important declaration hither is animation-name, which binds the keyframe my-blitheness to our div element. Below that are several additional declarations that impact the timing and beliefs of the animation.

The animation itself is created with a keyframe, indicated past the @keyframes rule. A keyframe defines the animation'south starting state (inside from{}) and its end country (inside to{}). The keyframe my-blitheness changes three style backdrop of our div: groundwork-color, width, and acme. When these three backdrop are animated at once, information technology produces a coherent blitheness.

In our instance, we only take one keyframe. Documents with multiple types of animations may have multiple keyframes, each bound to a different chemical element.

CSS Animation Examples

Below, nosotros've compiled 24 CSS animation examples ranging from bones interaction effects to literal works of art (at least according to me). Feel costless to utilise them for inspiration in your own projects.

1. CSS Mouse Hover Transition Effect

Starting things off light, this animation shows a uncomplicated but constructive text highlight effect triggered by a mouseover action. Information technology's a great way to add some extra flair to your folio links.

See the Pen CSS mouse-out transition effect by Adam Argyle (@argyleink) on CodePen.

View the lawmaking here.

2. Simple Loading Spinners

CSS animations can be used to create furnishings that nosotros're all familar with — these spinning load icons are one such example. Their meaning is near universally understood, and they're calorie-free on code as well. This particular instance as well shows how to achieve a similar effect with a scalable vector graphic.

Meet the Pen Uncomplicated HTML & SVG Loading Spinners past Stephen Delaney (@sdelaney) on CodePen.

View the lawmaking here.

3. Scrolling Text Animation

Another cool style to enhance your text, this lawmaking snippet applies a slot-automobile-like effect which rotates words in and out of view. This is a common technique on websites that need to convey the versatility of their creations. Is your production efficient, convenient, and sustainable? Plug those words into an animation like this ane.

See the Pen Text animation by Yoann (@yoannhel) on CodePen.

View the lawmaking here.

4. Animated Submit Button

Users appreciate the small, unexpected please moments that savvy designers like to sprinkle throughout their web pages. This submit button is a make clean, pleasing mode to provide visual feedback indicating that an action has been completed, such as a form being submitted.

Run into the Pen Submit Button pure css animation past Dead Pixel (@dead_pixel) on CodePen.

View the code here.

5. Hover-Responsive Logo

Check out the logo in the bottom right corner of the pen below — this animation applies a subtle animation on mouse-hover. Information technology's another visual cue for users that makes navigating your website a tad more enjoyable.

See the Pen Template: Logo past Alex Katz (@katzkode) on CodePen.

View the code hither.

6. Opening Envelope

Ane of my favorite examples, this elegant animation pays close attention to detail. From the downwards motion as the envelope opens, to the details on the paper, to the shadow underneath, it'south clear how small touches add together up to one smooth, coherent blitheness. This would make a great button or curlicue animation.

Run across the Pen Animated CSS Postal service Button by Jake Giles-Phillips (@jakegilesphillips) on CodePen.

View the code here.

seven. Hot Java

The snippet beneath exemplifies how unproblematic animations can go forth mode. In this instance, applying CSS animation to translation, scale, and opacity fade adds life to an otherwise plainly drawing.

Meet the Pen Hot Coffee past Zane Wesley (@zanewesley) on CodePen.

View the code here.

8. Coffee Machine

We love our java, and then here's one more. In this instance, the animation doesn't steal focus. Rather, it enhances to careful design around it to make the whole chemical element feel more immersive.

Come across the Pen Coffee Machine Pure CSS Animation by Henrique Rodrigues (@hjdesigner) on CodePen.

View the code hither.

9. Button Wiggle

Demand to describe a user to a particular action? In lieu of a color flash or a modal, consider calculation a quirky wiggle effect to a button. It'due south a friendly simply effective way to capture attention without seeming invasive or significantly disrupting the company'south flow.

See the Pen Save push button wiggle by Donovan Hutchinson (@donovanh) on CodePen.

View the code here.

x. Pacman

I don't recommend placing this 1 on your site for adventure of copyright infringement, but it's fun to look at regardless.

See the Pen Pacman by Riccardo (@Ferie) on CodePen.

View the lawmaking hither.

11. Three Dots Loading

Another example of CSS animations creating a loading effect that many of united states are familiar with. A uncomplicated scale alter is all that'south needed to say, "Just a moment, delight."

See the Pen CSS Loader with dots past Alexey Peterson (@petersonby) on CodePen.

View the code here.

12. File Drawers

To liven up your menus, consider something like the pure CSS file drawers below. Its cabinets open slightly on mouse hover, helping your primary navigation stand out from others.

See the Pen Pure CSS Drawers ʕノ•ᴥ•ʔノ ︵ ┻━┻ by Jhey (@jh3y) on CodePen.

View the lawmaking hither.

thirteen. Color Fan

This side by side case works specially well for pattern-centric business organization websites — endeavor animating your color palettes to create a fan-out issue, and modify things upward from bones colored squares.

See the Pen Color Palette with Pure CSS Blitheness past Nitish Khagwal (@nitishkmrk) on CodePen.

View the code here.

fourteen. 3D Toggle Switch

The on/off switch is a staple of UI design. This case puts a three-dimensional spin on the concept, consummate with a smooth animation for toggling state. Hither, the developer has modified the CSS checkbox input chemical element into something far more interesting.

Meet the Pen Toggle Switch with a Hole Handle by Jon Kantner (@jkantner) on CodePen.

View the code here.

15. Submarine

CSS works well for flat, colorful illustrations and animations. The code below combines several furnishings to describe a — quite frankly — adorable submarine. The only change I would advise is making information technology yellowish.

See the Pen Submarine with CSS by Alberto Jerez (@ajerez) on CodePen.

View the lawmaking here.

16. Animated Title Text on Hover

Olivia Ng'south "Hover Effect for Headers" example explores several means to add dynamism to title text. It shows how just a couple of keyframes tin can drag your headings.

See the Pen Hover Upshot for Headers by Olivia Ng (@oliviale) on CodePen.

View the lawmaking here.

17. Floating Image

The "floating" effect is a subtle, simple, and constructive employ of CSS animations. In this case, information technology's used to display an icon with first-class results.

Run into the Pen Floating Blitheness - CSS by Mario Duarte (@MarioDesigns) on CodePen.

View the code hither.

18. Astronaut

Hither's some other smart use of the floating result, paired with a friendly out-of-this-earth analogy. However another example of a subtle CSS animation effect to enhance the feel of a page chemical element.

See the Pen Pure Css Astronaut Animated by Coding Artist (@Coding-Artist) on CodePen.

View the code here.

nineteen. Minimal Cat

This example makes clever use of negative space combined with some well-timed CSS animations. It's a simple design that conveys a lot of personality with the CSS transform property alone.

See the Pen Pure CSS cat blitheness past Johan Mouchet (@johanmouchet) on CodePen.

View the code here.

20. Growing/Shrinking Bars

CSS can exist used to animate visualizations and more than effectively communicate your findings. This example demonstrates how colors and speed tin can create different feels for dynamic bar graphs — CSS animations let you change the speed and number of repetitions in your animations.

See the Pen Logo playtime by Dan Peddle (@dazld) on CodePen.

View the lawmaking here.

21. Light amplification by stimulated emission of radiation Tag

I'll admit this is one of our more complex examples. All the same, information technology makes for a unique and captivating loading display to hold attention for a cursory menstruation.

See the Pen The Glowing Loader - Pure CSS Blitheness by Maxime Rossignol (@Maxoor) on CodePen.

View the code here.

22. Candles

Hither'due south a brilliant example of how CSS animations tin can tell a story, albeit a brusque i. Y'all'll likely need a lot of practice to pull something like this off, just it'due south certain to stick out to those visiting your site for the first fourth dimension.

See the Pen Funny Candle Pure CSS Animation by Kevin David (@kevin_David_k) on CodePen.

View the lawmaking hither.

23. Speedy Truck

Chris Johnson's "Speedy Truck" makes smart use of parallax to simulate a truck'southward drive through a natural setting. While minimalist, this pen makes up for it with several creative uses of the transform property — there's fifty-fifty a little bump in the route.

See the Pen Speedy truck by Chris Johnson (@ChrisJohnson) on CodePen.

View the lawmaking hither.

24. Snow World

The coziest example we could find, this snow globe animation adds an ambiance to your page that you won't get with a nonetheless prototype. Notice how the snowfall animates only within the confines of the "glass" world.

Run across the Pen Christmas Snow Globe Animation by Coding Artist (@Coding-Artist) on CodePen.

View the code here.

1 Final Example

As we've seen, just a touch of CSS blitheness tin can go a very long way in crafting a more immersive feel for your visitors. The best animations serve your content and experience without distracting or appearing contemporary — all of the above examples all strike this balance remarkably well.

However, nosotros couldn't resist adding one last example that blew u.s.a. abroad. This "Watch Tower" instance is probably across the telescopic of this slice in its complexity, but information technology's also a testament to what CSS and HTML lonely tin can accomplish.

See the Pen Watch Tower Pure CSS Animation by Travis Doughty (@tdoughty) on CodePen.

For more of these crawly vignettes similar this one, check out the creator'due south CodePen profile and beginning thinking upwards ideas for yourself.

New Call-to-action

css introduction

Originally published Mar one, 2021 7:00:00 AM, updated May sixteen 2022