CSS3 Linear Gradient - Left to Right

The following example shows a linear gradient that starts from the left and ends at the right. It starts red, transitioning to blue:

HTML file: Displayed by browser:
<style>
#grad {
  background: -webkit-linear-gradient(left, red , blue); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(right, red, blue); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(right, red, blue); /* For Firefox 3.6 to 15 */
  background: linear-gradient(to right, red , blue); /* Standard syntax */
}
#grad1 {
  height: 200px;
  background: -webkit-linear-gradient(left, red , blue); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(right, red, blue); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(right, red, blue); /* For Firefox 3.6 to 15 */
  background: linear-gradient(to right, red , blue); /* Standard syntax (must be last) */
}
</style>
<body>
<div id="grad">This has no height set on this element.</div>
<br />
<div id="grad1">This element is set to be 200 pixels high.</div>
</body>
This has no height set on this element.

This element is set to be 200 pixels high.

Note: The webkit declaration (for Safari) uses the originating location (left), while the others use the destination location (right).

Back button Table of Contents Next button