CSS3 Linear Gradient - Diagonal

You can make a gradient diagonally by specifying both the horizontal and vertical starting positions. The following example shows a linear gradient that starts at top left (and goes to bottom right). It starts red, transitioning to blue:

HTML file: Displayed by browser:
<style>
#grad {
  background: -webkit-linear-gradient(left top, red , blue); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(bottom right, red, blue); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(bottom right, red, blue); /* For Firefox 3.6 to 15 */
  background: linear-gradient(to bottom right, red , blue); /* Standard syntax */
  color:white;
}
#grad1 {
  height: 200px;
  background: -webkit-linear-gradient(left top, red , blue); /* For Safari 5.1 to 6.0 */
  background: -o-linear-gradient(bottom right, red, blue); /* For Opera 11.1 to 12.0 */
  background: -moz-linear-gradient(bottom right, red, blue); /* For Firefox 3.6 to 15 */
  background: linear-gradient(to bottom 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 top), while the others use the destination location (bottom right).

Back button Table of Contents Next button