CSS3 Animation Will Rock Your World

Jonathan wrote this on in . It has 13 comments.

There's been a lot of hullaballoo on the 'tubes about the Safari 4 beta – fast javascript engine, new UI elements (that we're not all sold on), coverflow, full-page zoom and about 140 other features. What's got the online world all hot and bothered though is CSS animation, part of the proposed spec for CSS3.

We've had a chance to play around with CSS animations on some of our internal tools and let's not kid ourselves...CSS animation is slick. Safari renders it incredibly quickly and smoothly (so much so that the Safari 4 welcome splash is made almost completely in HTML5 and CSS3). So what can CSS animation do and, more importantly, what can't it do?

This Will Look Weird in Safari (and Chrome)

...because it's a 2 degree tilt. Safari 4 supports an array of transforms; functions that can be applied to almost any element to make a visual (but not structural) change. It has all kinds of fun transforms from rotate and skew to generated gradients, masking and box reflection.

As with any tool there are a lot of hilarious ways to overuse these effects but used well you can create some pretty incredible visuals with a laughably small amount of work. In addition to transforms Safari supports transitions, basically a means of telling the browser that when a CSS property changes (say, for :hover) to make that change over a set period of time, with a transition timing (easing in or out, for example).

That block tells the browser that when the element opacity changes, make the change over 2 seconds (instead of an instant change). Transitions support most any CSS property including position, size – and more interestingly, CSS transforms like scale and rotate or even generated gradients and masks. Combining these new effects can create some pretty complex visual effects and opens up a whole big toolbox for us.

CSS animations round out the new visual effects by allowing you to define an animation and specify keyframes to alter any CSS property. For example, this animation has three stages and changes the object from translucent to opaque, increases the size by 1.2x, then collapses it back to regular size and opacity. This repeats 10 times to create a pulsing effect.

To execute this animation I assign the animation to an object, give it a duration and optionally define how many times I want it to iterate. Hover over the block below to see the animation.


Not in Safari? Watch the demo on YouTube.

These are quick and dirty examples but creating considered, powerful effects for the web is much, much easier in CSS3 than it has ever been before. So what can't we do with CSS3?

Why CSS3 Won't Kill Javascript

There's been some discussion that CSS3 breaks a cardinal law of good web design: HTML is for content, CSS is for display and Javascript is for interaction. By allowing elements to shift around CSS3 has stolen a little of Javascript's thunder. Previously if you wanted an object to fade in or out, smoothly move around or rescale you had to use some jQuery (or otherwise) trickery. Some say that CSS3 has outstepped the bounds of CSS by no longer just dealing with visual display...I don't buy it.

Even with animations and transitions CSS3 still only governs the visual display of an object – albeit the visual display over time. With the exception of :hover (which has always allowed CSS to act on user actions) CSS3 still can't execute itself based on interaction. We can do a few tricks by playing with durations and delayed start times (properties supported by CSS animation) but Javascript is still required to create pages that react to user interaction.

What CSS3 does do for us is make complex Javascript interactions suddenly much, much faster to implement. Instead of using jQuery or something else to have elements react visually to input we can use Javascript to simply execute a CSS animation (or add a class with an animation included). Javascript has actually been extended to execute CSS animations and even listen to objects for animation starts and stops.

CSS animation is cool...really, really cool. Even as what is still a possible addition to CSS3 we can already see the potential in these new tools. They'll be used well and used poorly, as with any tool, but this gets us a head start on a much more dynamic web experience (without resorting to Flash). Check out the Safari Visual Effects Guide for a primer on the tools available. This is brand new territory, so there's a lot of opportunity to get out in front and explore the possibilities. Go play around with it!

See more Product Engineering and Design Jobs on Job Board from ZURB.

13 comments

Martin (ZURB) says

I too say there's nothing wrong with it as it's a part of the natural CSS evolution - it's just not possible for it to stay the way we know it from CSS1.

although it's not very practical at the moment -- the majority hardly couples with CSS2.


Paul Lloyd (ZURB) says

I've always thought it a little interesting how web technologies are progressing. If you take a very simplified view:

  • Flash replaces Video
  • JavaScript replaces Flash
  • CSS replaces JavaScript
  • …

So the question is, what over time will replace CSS. I'm going to say ASCII art ;-)


Jonathan (ZURB) says

@Martin How so? I haven't run across a lot of issues integrating the new pieces with our current CSS framework, but I haven't had a huge amount of time to play around...am I missing something? (I may well be, in fact the guys in the office would almost certainly say I miss all kinds of things)

@Paul Honestly there's still a place for most of those tools, but the evolution of web technologies is pretty cool to see! And you just gave me a hilarious idea for a website built completely in monospaced text. :D


Jeremy (ZURB) says

Some of these developments are exciting for what they hold for the future. Simple, understated animations and even audio can add more of the "feel" to look-and-feel interaction and visual designers create online. Two things:

1) Nobody can really see them yet because only a tiny group of Mac-loving designers are using browsers that support this stuff. How long will it take for these kinds of techniques to be widely supported by the web browser market? Two years? Three? Five?

2) What are the implications for animation effects if they're going to take that long to be supported? Well, for one it means these effects which seem neat-o today are really going to need to compete in a web browser market of the near future, NOT today's market. How much will have changed by then? Do these animations aim high enough to impress web users when you think what other products they'll be exposed to by then?


Jonathan (ZURB) says

@Jeremy Well Firefox 3.1 will support most of these new features, and the great thing about Firefox is that new versions tend to wipe out old versions. Chalk it up to Firefox users being more likely to upgrade or how pushy Firefox is about new versions, but Firefox 3 wiped the floor with Firefox 2 in a hurry.

That being said: yeah, it'll be a while till these are really widely supported and who knows if the IEs will get their act together within the next decade – but as far as competing I think what will make these new tools really great is that for as fast as the web itself moves, web technology doesn't move that fast. HTML4 has been around for over 10 years, Flash gets a new version now and then that doesn't really change much, Javascript seldom gets DOM extensions...people do new things with the old technology all the time, but new technology is much more rare. I think CSS3 (combined with HTML5) represents truly new technology – just have to see what people do with it over time. Hopefully cool things and not just <blink> 2.0 :)


julian (ZURB) says

To Be Honest...

Simply when it comes to CSS3, Javascript, Ajax, Ajax Frameworks and Java it is simply easier to take a safe route and use as much of older cross platform technology to get the safest results.

All these languages have there Achilles Heals: JQuery only seems to work properly on IE,FF and OPERA where CSS3 only works on Chrome and safari...Even standard javascript differs from one sight to the other and they all display differently on different browsers.

How Safe are we when we code?

The more flashy your webpage is the more temperamental it becomes...So it is better to use older technologies that do run across all browsers and do not negatively effect SEO such as basic Javascript,the original older CSS , php4 and above.

I suggest that you try to program as much of your website in php, perl, ruby on rails (backend languages) that output pure html as it will always be SEO friendly and cross browser compatible.

Presentation and Browser Compatibility are the most important 2 concepts when it comes to web development and to be honest people don't like web pages that take ages to load and are simply looking for the fastest answers to there needs. On top of that, the more you code: the harder it becomes to debug and the longer it takes to produce a result. The more intricate your code becomes the harder it is for others to follow.

If you take a look at my website you will see a basic, Well SEO based website that is presentable and loads quickly. Although please be reminded that if you wish to use my services that this website is not intended to be highly functional and was build to allow for low bandwidth resource saving as it is hosted in South Africa where we have to pay $100 every time we use 5 gigs of bandwidth cap

Hope this was helpful Regards Julz


drive electrical machine power system (ZURB) says

Keep up da good work. i just added your RSS feed My bro am going to bookmark and read more often Talk Later


geico commercials (ZURB) says

Thanks yours truly found just dha info yours truly already searched everywhere and just couldnt find. What a very nice website. Like this website this site is one of my favs. Would you be interested in exchanging site roll Cu Soon


lexmark dot matrix printer (ZURB) says

Moin Awesome info! i was honestly just thinking about something similar to this da other day so, it was almost weird when i ran across this. You would be surprised how many people simply have no idea when it comes to this kind of stuff. Anyway, thanks for getting this very great info out there and i am sure i am not da only one who appreciates you taking da time to post this for da masses. What do you know about achievement?


ac to dc power supply adapter (ZURB) says

my homie was reading someone elses site and saw you on their blogroll.


Reply SMS Hindi (ZURB) says

CSS3 is it’s capability to animate elements without the use of javascript, but if you combine the two it is more powerful.


Jacob (ZURB) says

Very cool. I've just added a funky looking OS X Dock style bounce animation along with a slight pulsating button on www.imagexyapp.com. It's a shame that it's not available on all browsers (still) as trying to make things fully degradable can be a pain if you add in pre-loading of images before animations start etc.



Get a job, nerd!

via Job Board from ZURB