WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS3 Gradients


Gradient Background

CSS3 angles let you show smooth advances between at least two indicated colors.

Earlier, you needed to utilize pictures for these impacts. Be that as it may, by utilizing CSS3 angles you can decrease download time and data transfer capacity use. What's more, components with slopes look better when zoomed, since the angle is created by the browser.

CSS3 characterizes two sorts of gradients:

  • Linear Gradients (goes down/up/left/right/diagonally)
  • Radial Gradients (characterized by their center)

Browser Support

The numbers in the table determine the main program form that completely underpins the property.

Numbers pursued by - webkit-, - moz-, or - o-determine the main form that worked with a prefix.

Property
linear-gradient 26.0
10.0 - webkit-
12.0 10.0 16.0
3.6 - moz-
6.1
5.1 - webkit-
12.1
11.1 - o-
radial-gradient 26.0
10.0 - webkit-
12.0 10.0 16.0
3.6 - moz-
6.1
5.1 - webkit-
12.1
11.6 - o-
repeating-direct gradient 26.0
10.0 - webkit-
12.0 10.0 16.0
3.6 - moz-
6.1
5.1 - webkit-
12.1
11.1 - o-
repeating-outspread gradient 26.0
10.0 - webkit-
12.0 10.0 16.0
3.6 - moz-
6.1
5.1 - webkit-
12.1
11.6 - o-

CSS3 Linear Gradients

To make a direct slope you should characterize something like two shading stops. Shading stops are the hues you need to render smooth changes among. You can likewise set a beginning stage and a course (or a point) along with the slope effect.

Syntax

foundation: direct gradient(direction, color-stop1, shading stop2, ...);

Linear Gradient - Top to Bottom (this is default)

The following model demonstrates a straight slope that begins at the best. It begins red, changing tohotpink:

Example

#grad {
    foundation: red;/* For programs that don't bolster inclinations */
    foundation: - webkit-direct gradient(red, yellow);/* For Safari 5.1 to 6.0 */
    foundation: - o-direct gradient(red, yellow);/* For Musical show 11.1 to 12.0 */
    foundation: - moz-straight gradient(red,hotpink);/* For Firefox 3.6 to 15 */
    foundation: direct gradient(red,hotpink);/* Standard language structure */
}
Try it yourself »

Linear Gradient - Left to Right

The following model demonstrates a straight angle that begins from the left. It begins red, progressing to yellow:

Example

#grad {
  foundation: red;/* For programs that don't bolster slopes */
  foundation: - webkit-straight gradient(left, red ,hotpink);/* For Safari 5.1 to 6.0 */
  foundation: - o-direct gradient(right, red, yellow);/* For Opera 11.1 to 12.0 */
  foundation: - moz-direct gradient(right, red,hotpink);/* For Firefox 3.6 to 15 */
  foundation: direct gradient(to right, red ,hotpink);/* Standard language structure */
}
Try it yourself »

Linear Gradient - Diagonal

You can make an angle corner to corner by indicating both the flat and vertical beginning positions.

The following precedent demonstrates a straight angle that begins at upper left (and goes to base right). It begins red, changing tohotpink:

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
  foundation: - webkit-direct gradient(left top, red,hotpink);/* For Safari 5.1 to 6.0 */
  foundation: - o-direct gradient(bottom right, red,hotpink);/* For Opera 11.1 to 12.0 */
  foundation: - moz-direct gradient(bottom right, red,hotpink);/* For Firefox 3.6 to 15 */
  foundation: direct gradient(to base right, red,hotpink);/* Standard linguistic structure */
}
Try it yourself »

Using Angles

If you need more command over the bearing of the angle, you can characterize a point, rather than the predefined bearings (to base, to top, to appropriate, to left, to base right, etc.).

Syntax

foundation: straight gradient(angle, color-stop1, shading stop2);

The edge is indicated as an edge between a flat line and the angle line.

The following precedent tells the best way to utilize points on straight gradients:

Example

#grad {
  foundation: red;/* For programs that don't bolster slopes */
  foundation: - webkit-direct inclination(- 90deg, red,hotpink);/* For Safari 5.1 to 6.0 */
  foundation: - o-straight angle(- 90deg, red,hotpink);/* For Opera 11.1 to 12.0 */
  foundation: - moz-straight angle(- 90deg, red,hotpink);/* For Firefox 3.6 to 15 */
  foundation: straight angle(- 90deg, red,hotpink);/* Standard linguistic structure */
}
Try it yourself »

Using Multiple Color Stops

The following precedent demonstrates a straight slope (through and through) with various shading stops:

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
  foundation: - webkit-direct gradient(red, yellow, mediumpurple);/* For Safari 5.1 to 6.0 */
  foundation: - o-straight gradient(red, yellow, mediumpurple);/* For Opera 11.1 to 12.0 */
  foundation: - moz-straight gradient(red, yellow, mediumpurple);/* For Firefox 3.6 to 15 */
  foundation: straight gradient(red,hotpink, mediumpurple);/* Standard grammar */
}
Try it yourself »

The following precedent tells the best way to make a direct angle (from left to ideal) with the shade of the rainbow and some text:

Slope Background

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
 /* For Safari 5.1 to 6.0 */
  foundation: - webkit-straight gradient(left,red,orange,yellow,mediumpurple,blue,indigo,violet);
  /* For Opera 11.1 to 12.0 */
  foundation: - o-straight gradient(left,red,orange,yellow,mediumpurple,blue,indigo,violet);
 /* For Fx 3.6 to 15 */
  foundation: - moz-straight gradient(left,red,orange,yellow,mediumpurple,blue,indigo,violet);
  /* Standard punctuation */
  foundation: straight gradient(to right, red,orange,yellow,mediumpurple,blue,indigo,violet);
}
Try it yourself »

Using Transparency

CSS3 slopes likewise bolster straightforwardness, which can be utilized to make blurring effects.

To include straightforwardness, we utilize the rgba() capacity to characterize the shading stops. The last parameter in the rgba() capacity can be an incentive from 0 to 1, and it characterizes the straightforwardness of the shading: 0 shows full straightforwardness, 1 shows full shading (no transparency).

The following model demonstrates a straight angle that begins from the left. It begins completely straightforward, changing to full shading red:

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
  foundation: - webkit-direct gradient(left,rgba(255,0,0,0),rgba(255,0,0,1));/*Safari 5.1-6*/
  foundation: - o-direct gradient(right,rgba(255,0,0,0),rgba(255,0,0,1));/*Opera 11.1-12*/
  foundation: - moz-straight gradient(right,rgba(255,0,0,0),rgba(255,0,0,1)); /*Fx 3.6-15*/
  foundation: direct gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1));/*Standard*/
}
Try it yourself »

Repeating a direct gradient

The rehashing direct slope() work is utilized to rehash straight gradients:

Example

A rehashing direct gradient:

#grad {
  foundation: red;/* For programs that don't bolster slopes */
 /* Safari 5.1 to 6.0 */
  foundation: - webkit-rehashing straight gradient(red, yellow 10%, mediumpurple 20%);
 /* Opera 11.1 to 12.0 */
  foundation: - o-rehashing straight gradient(red,hotpink 10%, mediumpurple 20%);
 /* Firefox 3.6 to 15 */
  foundation: - moz-rehashing straight gradient(red,hotpink 10%, mediumpurple 20%);
 /* Standard punctuation */
  foundation: rehashing straight gradient(red,hotpink 10%, mediumpurple 20%);
}
Try it yourself »

CSS3 Radial Gradients

A spiral slope is characterized by its center.

To make an outspread inclination you should likewise characterize no less than two shading stops.

Syntax

foundation: outspread gradient(shape measure at position, begin shading, ..., last-color);

By default, shape is oval, measure is most distant corner, and position is center.

Radial Gradient - Evenly Spaced Color Stops (this is default)

The following precedent demonstrates an outspread angle with uniformly dispersed shading stops:

Example

#grad {
  foundation: red;/* For programs that don't bolster slopes */
  foundation: - webkit-outspread gradient(red,hotpink, mediumpurple);/* Safari 5.1 to 6.0 */
  foundation: - o-spiral gradient(red,hotpink, mediumpurple);/* For Opera 11.6 to 12.0 */
  foundation: - moz-spiral gradient(red,hotpink, mediumpurple);/* For Firefox 3.6 to 15 */
  foundation: spiral gradient(red,hotpink, mediumpurple); /* Standard punctuation */
}
Try it yourself »

Radial Gradient - Differently Spaced Color Stops

The following precedent demonstrates a spiral slope with diversely divided shading stops:

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
  foundation: - webkit-spiral gradient(red 5%, yellow 15%, mediumpurple 60%);/* Safari 5.1-6.0 */
  foundation: - o-outspread gradient(red 5%,hotpink 15%, mediumpurple 60%);/* For Opera 11.6-12.0 */
  foundation: - moz-outspread gradient(red 5%,hotpink 15%, mediumpurple 60%);/* For Firefox 3.6-15 */
  foundation: outspread gradient(red 5%,hotpink 15%, mediumpurple 60%); /* Standard grammar */
}
Try it yourself »

Set Shape

The shape parameter characterizes the shape. It can take the esteem circle or oval. The default esteem is ellipse.

The following precedent demonstrates an outspread slope with the state of a circle:

Example

#grad {
  foundation: red;/* For programs that don't bolster angles */
  foundation: - webkit-outspread gradient(circle, red,hotpink, mediumpurple);/* Safari */
  foundation: - o-spiral gradient(circle, red,hotpink, mediumpurple);/* Opera 11.6 to 12.0 */
  foundation: - moz-spiral gradient(circle, red,hotpink, mediumpurple);/* Firefox 3.6 to 15 */
  foundation: spiral gradient(circle, red, yellow, mediumpurple); /* Standard punctuation */
}
Try it yourself »

Use of Different Size Keywords

The measure parameter characterizes the extent of the slope. It can take four values:

  • closest-side
  • farthest-side
  • closest-corner
  • farthest-corner

Example

A spiral inclination with various size keywords:

#grad1 {
  foundation: red;/* For programs that don't bolster inclinations */
 /* Safari 5.1 to 6.0 */
  foundation: - webkit-spiral gradient(60% 55%, nearest side, red,hotpink, dark);
 /* For Opera 11.6 to 12.0 */
  foundation: - o-outspread gradient(60% 55%, nearest side, red,hotpink, black);
  /* For Firefox 3.6 to 15 */
  foundation: - moz-outspread gradient(60% 55%, nearest side, red,hotpink, black);
 /* Standard sentence structure */
  foundation: outspread gradient(closest-side at 60% 55%, red,hotpink, black);
}

#grad2 {
  /* Safari 5.1 to 6.0 */
  foundation: - webkit-outspread gradient(60% 55%, most distant side, red,hotpink, black);
  /* Opera 11.6 to 12.0 */
  foundation: - o-outspread gradient(60% 55%, most remote side, red,hotpink, black);
 /* For Firefox 3.6 to 15 */
  foundation: - moz-outspread gradient(60% 55%, most distant side, red,hotpink, black);
  /* Standard sentence structure */
  foundation: spiral gradient(farthest-side at 60% 55%, red,hotpink, black);
}
Try it yourself »

Repeating an outspread gradient

The rehashing outspread slope() work is utilized to rehash spiral gradients:

Example

A rehashing outspread gradient:

#grad {
  foundation: red;/* For programs that don't bolster slopes */
 /* For Safari 5.1 to 6.0 */
  foundation: - webkit-rehashing outspread gradient(red, yellow 10%, mediumpurple 15%);
 /* For Opera 11.6 to 12.0 */
  foundation: - o-rehashing outspread gradient(red,hotpink 10%, mediumpurple 15%);
 /* For Firefox 3.6 to 15 */
  foundation: - moz-rehashing outspread gradient(red,hotpink 10%, mediumpurple 15%);
 /* Standard language structure */
  foundation: rehashing outspread gradient(red,hotpink 10%, mediumpurple 15%);
}
Try it yourself »