WordPress Code Snippets

A fresh mix of code snippets and tutorials

CSS transition effect for links

130

CSS transitions can add a nice effect to links. Here are some quick example snippets for your copy/paste enjoyment.

transition syntax

CSS3 transition property is widely supported, with the exception of Webkit and Opera Mini. Fortunately, it’s possible to apply transitions to those browsers as well using custom vendor prefixes. Before the examples, here is the basic syntax for CSS transition:

selector { transition: property duration timing-function delay; }

  • transition-property — name of animated property (eg, color)
  • transition-duration — duration of animation (in seconds or milliseconds)
  • transition-timing-function — animation speed curve (eg, ease, ease-out)
  • transition-delay — duration of animation delay (s or ms)

Vendor prefixes are used in the following examples to provide support for older browsers. All prefixes except -webkit- may be removed if you’re only supporting current versions (i.e., progressive enhancement).

Animate link colors

Animate link background colors

Animate color and background-color

More transition/animation examples

Check out the CSS transition examples at Perishable Press for some advanced techniques :)