Whether information technology's enhancing a button, killing time while a folio loads, or calculation some extra flair to a landing page, animation is an effective way to hold attention and delight viewers on your website.

While in that location are several ways to add together animated graphics to a web folio, ane of the easiest is using CSS animations, which require nothing more than some HTML and CSS know-how to pull off.

Download Now: Free HTML & CSS Hacks

If you want to add together CSS animations to your work, it can be helpful to wait at some successful uses of CSS animations starting time earlier 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 nosotros've compiled our favorite examples of CSS blitheness from CodePen — an online tool for creating and sharing code snippets in HTML and CSS — to assist become the creative juices flowing.

Simply first, a brief review of the topic at hand...

How do CSS animations piece of work?

CSS animation is a feature of CSS that allows you to animate a change in one or more than mode properties of an element, as well every bit control diverse aspects of the animation. Pure CSS animations require no additional code (eastward.m. JavaScript) or media (e.g. GIFs) — everything is done with HTML and CSS.

CSS animations are great for websites that want to add dynamic, engaging content without placing much more than weight on the page. Since they don't crave extra scripts, CSS animations are unlikely to slow downwards your pages.

To make a CSS blitheness, you demand three things: an HTML element to animate, a CSS rule which binds the blitheness to this element, and a group of keyframes that defines the styles at the showtime and cease of the animation. You lot tin also add declarations to further customize your animation, like speed and delay.

To demonstrate, here'due south a elementary case of a CSS blitheness:

See the Pen CSS Blitheness Example by Christina Perricone (@hubspot) on CodePen.

In this case, <div></div> is the chemical element nosotros're animating. Looking at the CSS, we see that our animation declarations are associated with the div selector. The virtually of import declaration here is animation-name, which binds the keyframe my-animation to our div chemical element. Below that are several boosted declarations that touch the timing and behavior of the animation.

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

In our example, nosotros only take one keyframe. Documents with multiple types of animations may take multiple keyframes, each bound to a different element.

CSS Blitheness Examples

Below, we've compiled 24 CSS animation examples ranging from basic interaction effects to literal works of art (at to the lowest degree according to me). Feel free to use them for inspiration in your own projects.

i. CSS Mouse Hover Transition Effect

Starting things off light, this blitheness shows a simple but constructive text highlight consequence triggered by a mouseover action. It's a neat way to add some extra flair to your page links.

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

View the code here.

2. Simple Loading Spinners

CSS animations tin can be used to create furnishings that we're all familar with — these spinning load icons are one such example. Their pregnant is almost universally understood, and they're light on code besides. This detail example also shows how to achieve a similar effect with a scalable vector graphic.

See the Pen Simple HTML & SVG Loading Spinners by Stephen Delaney (@sdelaney) on CodePen.

View the code here.

3. Scrolling Text Animation

Another cool way to enhance your text, this code snippet applies a slot-machine-similar outcome 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 product efficient, user-friendly, and sustainable? Plug those words into an animation similar this one.

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

View the code hither.

4. Animated Submit Push

Users capeesh the modest, unexpected delight moments that savvy designers like to sprinkle throughout their web pages. This submit button is a clean, pleasing way to provide visual feedback indicating that an activeness has been completed, such as a form beingness submitted.

See the Pen Submit Push button pure css animation by Dead Pixel (@dead_pixel) on CodePen.

View the code here.

5. Hover-Responsive Logo

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

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

View the code here.

6. Opening Envelope

1 of my favorite examples, this elegant animation pays close attending to detail. From the downward movement as the envelope opens, to the details on the paper, to the shadow underneath, it'due south clear how small touches add upward to ane smooth, coherent animation. This would brand a bully button or scroll animation.

Meet the Pen Blithe CSS Mail Push by Jake Giles-Phillips (@jakegilesphillips) on CodePen.

View the code here.

vii. Hot Coffee

The snippet below exemplifies how simple animations can become along way. In this case, applying CSS animation to translation, calibration, and opacity fade adds life to an otherwise evidently cartoon.

See the Pen Hot Java past Zane Wesley (@zanewesley) on CodePen.

View the lawmaking here.

viii. Coffee Car

We love our coffee, so hither'south one more. In this case, the animation doesn't steal focus. Rather, it enhances to careful design around information technology to make the whole element feel more immersive.

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

View the lawmaking here.

9. Button Jerk

Demand to describe a user to a item activity? In lieu of a color wink or a modal, consider adding a quirky wiggle outcome to a button. Information technology's a friendly simply effective way to capture attention without seeming invasive or significantly disrupting the visitor's menstruation.

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

View the code here.

10. Pacman

I don't recommend placing this one on your site for gamble of copyright infringement, but information technology's fun to look at regardless.

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

View the code hither.

11. Three Dots Loading

Some other instance of CSS animations creating a loading result that many of u.s. are familiar with. A unproblematic calibration change is all that's needed to say, "Just a moment, please."

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

View the lawmaking hither.

12. File Drawers

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

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

View the code here.

xiii. Colour Fan

This next instance works especially well for design-axial business websites — endeavor animating your color palettes to create a fan-out result, and change things upward from basic colored squares.

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

View the lawmaking hither.

14. 3D Toggle Switch

The on/off switch is a staple of UI design. This instance puts a three-dimensional spin on the concept, complete with a smoothen blitheness for toggling land. Here, the developer has modified the CSS checkbox input chemical element into something far more interesting.

See 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 effects to draw a — quite frankly — adorable submarine. The but change I would suggest is making it yellowish.

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

View the code hither.

16. Animated Title Text on Hover

Olivia Ng's "Hover Result for Headers" case explores several ways to add together dynamism to championship text. It shows how just a couple of keyframes can elevate your headings.

Come across the Pen Hover Effect for Headers by Olivia Ng (@oliviale) on CodePen.

View the code hither.

17. Floating Image

The "floating" outcome is a subtle, simple, and constructive apply of CSS animations. In this instance, it's used to display an icon with fantabulous results.

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

View the code here.

18. Astronaut

Here'south another smart use of the floating outcome, paired with a friendly out-of-this-world illustration. Withal some other example of a subtle CSS animation effect to enhance the feel of a folio element.

Encounter the Pen Pure Css Astronaut Blithe by Coding Creative person (@Coding-Artist) on CodePen.

View the code hither.

nineteen. Minimal True cat

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

See the Pen Pure CSS cat animation by Johan Mouchet (@johanmouchet) on CodePen.

View the lawmaking here.

twenty. Growing/Shrinking Bars

CSS can be used to breathing visualizations and more finer communicate your findings. This example demonstrates how colors and speed can create unlike 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 code here.

21. Laser Tag

I'll acknowledge this is one of our more than complex examples. Even so, information technology makes for a unique and captivating loading brandish to hold attending for a brief flow.

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

View the lawmaking here.

22. Candles

Hither's a vivid case of how CSS animations can tell a story, albeit a short one. You'll likely demand a lot of practise to pull something like this off, but information technology'due south sure to stick out to those visiting your site for the starting time fourth dimension.

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

View the code hither.

23. Speedy Truck

Chris Johnson'southward "Speedy Truck" makes smart use of parallax to simulate a truck'south bulldoze through a natural setting. While minimalist, this pen makes up for information technology with several creative uses of the transform holding — there'southward even a piddling bump in the road.

Run into the Pen Speedy truck past Chris Johnson (@ChrisJohnson) on CodePen.

View the code hither.

24. Snow Earth

The coziest case nosotros could find, this snow globe animation adds an ambiance to your folio that yous won't get with a yet image. Observe how the snow animates only within the confines of the "glass" globe.

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

View the code here.

One Concluding Example

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

However, we couldn't resist calculation one final instance that blew the states abroad. This "Watch Tower" example is probably across the scope of this slice in its complexity, just it'south too a testament to what CSS and HTML alone tin attain.

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

For more of these awesome vignettes similar this one, check out the creator's CodePen profile and start thinking up ideas for yourself.

New Call-to-action

css introduction

Originally published Mar i, 2021 seven:00:00 AM, updated May 16 2022