Unlimited Plugins, WordPress themes, videos & courses! Unlimited asset downloads! From $16.50/m
  1. Code
  2. HTML & CSS

Quick Tip: Understanding CSS3 Gradients

Read Time:3 minsLanguages:

Creating an image only for the purpose of displaying a gradient is inflexible, and is quickly becoming a bad practice. Unfortunately, at the time of this writing, they very well might still be required, but hopefully not for much longer. Thanks to Firefox and Safari/Chrome, we can now create powerful gradients with minimal effort. In this video quick tip, we'll examine some of the differences in syntax when working with the -moz and -webkit vendor prefixes.


While Mozilla and Webkit generally adopt the same syntax for CSS3 properties, they unfortunately don't quite agree when it comes to gradients. Webkit was first to embrace gradients, and uses the following structure:


Don't worry if your eyes gloss over at that syntax; mine did too! Just note that we require a comma-separated list of parameters.

  • What type of gradient? (linear)
  • X and Y axis coordinates of where to begin. (0 0 - or left-top corner)
  • X and Y axis coordinates of where to conclude (0 100% - or left-bottom corner)
  • What color to begin with? (from(red))
  • What color to conclude with? (to(blue))


Firefox, which implemented gradient support with version 3.6, prefers a slightly different syntax.

  • Note how we've placed the type of gradient, linear, within the vendor extension.
  • Where should the gradient begin? (top - we could also pass in degrees, as in -45deg)
  • What color to start with? (red)
  • What color to conclude with? (blue)


What if you don't need a 100% gradient from one color to another? This is where color stops come into play. A common design technique is to apply a short and subtle gradient, like this:

Subtle Gradients
Note the subtle off-white to white gradient at the top.

In the past, the standard implementation was to create an image, set it as the background of an element, and set it to repeat horizontally. However, with CSS3, this is a cinch.

This time, we set the gradient to conclude at 8%, rather than 100%, which is the default. Note that we're also applying a border top to add contrast; this is very common.

If we wish to add a third (or Nth) color, we can do:

  • With the -moz version, we designate that, at 20% of the element height, we should now be at the color red.
  • For -webkit, we use color-stop, and pass in two parameters: where the stop should occur, and what the color should be.

Important Notes About CSS Gradients

  • Use them as much as you can. If it's okay to let IE users see a solid color, I encourage you to use this method.
  • IE6/7/8, Opera, Safari 3, and Firefox 3 cannot render CSS3 gradients. Firefox and Safari users generally upgrade often, so that's not as big of a deal.
  • Always apply a default, solid color, background for browsers that won't understand the vendor prefixes.
  • Never use a red to blue gradient, as I did for the examples.
  • Webpages don't need to look the same in every browser! :)

Thanks for reading/watching!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.