SpyreStudios

Web Design and Development Magazine

  • Design
  • Showcase
  • Inspirational
  • Tutorials
  • CSS
  • Resources
  • Tools
  • UX
  • More
    • Mobile
    • Usability
    • HTML5
    • Business
    • Freebies
    • Giveaway
    • About SpyreStudios
    • Advertise On SpyreStudios
    • Get In Touch With Us

When To Use JavaScript vs. CSS3 for Animation

January 26, 2015 by Jake Rocheleau

Animated web content has been around for years in the form of GIFs and Flash content. But as those older methods fall to the wayside newer techniques have grown in their place. Back in the early 2000s JavaScript was widely-regarded as the best solution for animated web content. Then an update to CSS created the CSS3 specification with all sorts of fancy new properties.

Among these new properties are some amazingly powerful codes for animated content on the page. It’s now possible for frontend web developers to craft a dynamic website using only HTML and CSS code. But is this really the most viable option?

featured javascript codes sample

I’d like to cover a few talking points related to website animation comparing the differences between JavaScript and CSS3. If you’re a developer then it’s worth learning both languages to empower yourself and your projects. If you’re a designer it’s still good to understand these concepts to better communicate your ideas with developers. Web animation is most certainly here to stay – the only question is, where will it advance from here?

Speed & Efficiency

By skimming this wonderful post about CSS vs JS animation speed it’s easy to see that CSS3 is a preferred natural option for supported web browsers. Regular-old JavaScript is also a great option if you want to hardcode all of that content. But it turns out that jQuery itself is a little slower – not super noticeable but still there.

jQuery wasn’t created to be an animation library. In fact, a secondary library jQuery UI was created with some animation functionality, but that still wasn’t the overall goal. I would still honestly suggest using jQuery for simple stuff because it’ll be much more supported in comparison with CSS3 transition effects.

But JavaScript as a whole is tricky business. Unless you have some advanced development skills you’re really gonna need to work hard to get the animations you desire. It seems that CSS3 is growing much faster with both transitions and keyframe animation. The biggest downside is a serious lack of backwards compatibility.

So when it comes to speed I would say both CSS3 and typical JavaScript are good options. It really depends how much browser support you need. In fact you may even try out a pre-built library for these effects. For CSS3 there’s the very popular Animate.css while JavaScript has Velocity.js(among others).

Levels of Control

From a standpoint of objective control JavaScript seems to have greater jurisdiction over the municipality of Animationville. With JavaScript it’s possible to create any type of easing effect paired with any element on the page. Rotation, scale, explosions, anything you can imagine is possible with enough code.

But CSS3 is enticing because the animation properties are added directly onto the element.

css3 css coding development graphics

The biggest downside with CSS3 is a lack of trigger events. JavaScript contains a panoply of events such as mouseover, right-click, click-and-drag, or even targeting specific keypresses on the keyboard. CSS3 animation is handled through a change in class or pseudo-class. This relies on selectors like :hover or :active to perform the animation.

So when it comes to absolute power I would have to say JavaScript offers much more control. This is simply because JavaScript has been around longer and has been gestating for years with updates and code releases. CSS3 is still a newer invention that has been gaining a lot of momentum, but still has a long way to go.

Practical Usage

Many times you’ll find animation effects online that just seem ridiculous. It’s really cool to build an animated printer or snowfall effect – but this kinda stuff doesn’t have much practical value. Web design is always about the user first. Therefore your animation should enhance the user experience and not just add pretty frills onto the page.

So what does have value? Well for starters you might try loading animations like spinners and animated graphics. These elements denote when a page is in the middle of loading or preloading resources. You might also want to create dynamic effects in a carousel or perhaps a contact form with label hints for each field.

Getting down into the meat & potatoes there is a lot of pragmatic stuff you can build with animated effects. For example, dropdown menus and tabbed widgets are built upon hidden content. When a user interacts with the menu or tab links the invisible content is swapped into view.

css3 animated dropdown accordion menu

My honest recommendation when it comes to animated effects is to keep it all simple. If you’re gonna go overboard make sure that it really fits into the layout style. For example, a cartoony layout can get away with exaggerated animation effects to replicate the squash and stretch effect found in cartoons. Try out lots of different ideas and see what type of animation you like the most.

CSS3 Keyframes

If you’re adamant to learn in-depth CSS3 animation then you’ll have to get into keyframing. The generic transition effects can be useful for simple stuff, but they really just scratch the surface. Keyframe animation gives the developer so much more control over which elements are moving, how they’re moving, and where they end up.

CSS-Tricks has an excellent guide on keyframe syntax which I recommend you attempt to memorize. There are a few browser prefixes which can be difficult to retain in your head, so alternatively you might store this code as a snippet. Also check out the Mozilla @keyframes reference documentation for in-depth info.

mozilla developers network css3 keyframes

Frontend development has advanced so quickly over the past few years. I never would have imagined something like keyframes being implemented into CSS when I first began studying web design in 2005. So much has changed and if you want to keep up with the times, you’ll have to at least try to change your methods as well.

Routines for Practicing Frontend Development

Additionally if you want to push your CSS skills to the next level it’s worth learning about SASS. That stands for Syntactically Awesome StyleSheets and it basically allows developers to compile CSS code much like a programming IDE. If you take the time to learn SASS it will save you hours of copying & pasting code. The Animate.css library even has a SASS version to give you a starting point.

Final Thoughts

So between CSS and Javascript, which is the better choice? As with all these fascinating conundrums the answer is kinda lame: it really depends on the circumstances. My personal preference is using CSS3 for nonessential animation like a button hover effect. JavaScript feels a bit cleaner for integrated animation like dropdown menus and carousel rotators only because of the wide browser support.

Ultimately it is your decision and there’s no wrong answer. Take this as an exploration into modern web animation and mix it up with each project. Don’t be afraid of pushing boundaries to see how far you can go.

Filed Under: UX Tagged With: animation, css3, javascript, web design

Recent Posts

  • 31 Fresh Design Elements for Spring and Easter
  • 10 Templates for Music Concert Flyers
  • How to Build a Web Scraper Using Node.js
  • Best PHP Books, Courses and Tutorials in 2022
  • How to Get Your First Web Design Client

Archives

  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • September 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • July 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • October 2012
  • September 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • May 2008
  • April 2008

Categories

  • Accessibility
  • Android
  • Apps
  • Art
  • Article
  • Blogging
  • Books
  • Bootstrap
  • Business
  • CSS
  • Design
  • Development
  • Ecommerce
  • Fireworks
  • Flash
  • Freebies
  • Freelance
  • General
  • Giveaway
  • Graphic Design
  • HTML5
  • Icons
  • Illustrator
  • InDesign
  • Infographics
  • Inspirational
  • Interview
  • Jobs
  • jQuery
  • Learning
  • Logos
  • Matrix
  • Minimalism
  • Mobile
  • Motion Graphics
  • Music
  • News
  • Photoshop
  • PHP
  • Promoted
  • Rails
  • Resources
  • Showcase
  • Tools
  • Tutorial
  • Twitter
  • Typography
  • Uncategorized
  • Usability
  • UX
  • Wallpapers
  • Wireframing
  • WordPress
  • Work

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

SpyreStudios © 2022