Beginner’s Sample Guide To CSS3 – Gradients
Continue from the previous article, in this part we give another simple samples about gradient on css3. CSS3 gradient let you display smooth transitions between two or more specified colors….
From our archive. Written in 2014; some details may have moved on.

Continue from the previous article, in this part we give another simple samples about gradient on css3. CSS3 gradient let you display smooth transitions between two or more specified colors.
CSS3 defines two types of gradients:
- Linear Gradients (goes down/up/left/right/diagonally)
To create a linear gradient you must define at least two color stops. Color stops are the colors you want to render smooth transitions among. You can also set a starting point and a direction (or an angle) along with the gradient effect.
Linear Gradient – Top to Bottom (this is default)
#gradient1
{
background: -webkit-linear-gradient(yellow, green); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(yellow, green); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(yellow, green); /* For Firefox 3.6 to 15 */
background: linear-gradient(yellow, green); /* Standard syntax (must be last) */
}
Linear Gradient – Left to Right
#gradient2
{
background: -webkit-linear-gradient(left, yellow , green); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, yellow, green); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, yellow, green); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, yellow , green); /* Standard syntax (must be last) */
}
Linear Gradient – Diagonal
#gradient3
{
background: -webkit-linear-gradient(left top, yellow , green); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(bottom right, yellow, green); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(bottom right, yellow, green); /* For Firefox 3.6 to 15 */
background: linear-gradient(to bottom right, yellow , green); /* Standard syntax (must be last) */
}
Linear Gradients – Transparency
#gradient4
{
background: -webkit-linear-gradient(left, rgba(255,0,0,0), rgba(255,0,0,1)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(right, rgba(255,0,0,0), rgba(255,0,0,1)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(right, rgba(255,0,0,0), rgba(255,0,0,1)); /* For Firefox 3.6 to 15 */
background: linear-gradient(to right, rgba(255,0,0,0), rgba(255,0,0,1)); /* Standard syntax (must be last) */
}
Linear Gradients – Multiple colors
#gradient5
{
background: -webkit-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* For Fx 3.6 to 15 */
background: linear-gradient(red, orange, yellow, green, blue, indigo, violet); /* Standard syntax (must be last) */
}
Linear Gradients – Multiple colors left to right
#gradient6
{
background: -webkit-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(left, red, orange, yellow, green, blue, indigo, violet); /* For Fx 3.6 to 15 */
background: linear-gradient(to right, red, orange, yellow, green, blue, indigo, violet); /* Standard syntax (must be last) */
}
Linear Gradients – Repeating
#gradient7
{
background: -webkit-repeating-linear-gradient(red, yellow 10%, green 20%); /* For Safari 5.1 to 6.0 */
background: -o-repeating-linear-gradient(red, yellow 10%, green 20%); /* For Opera 11.1 to 12.0 */
background: -moz-repeating-linear-gradient(red, yellow 10%, green 20%); /* For Firefox 3.6 to 15 */
background: repeating-linear-gradient(red, yellow 10%, green 20%); /* Standard syntax (must be last) */
}
Linear Gradient – Angles
If you want more control over the direction of the gradient, you can define an angle, instead of the predefined directions (to bottom, to top, to left, to bottom right, etc.).
Angles 0deg
#gradient8
{
background: -webkit-linear-gradient(0deg, green, blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(0deg, green, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(0deg, green, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(0deg, green, blue); /* Standard syntax (must be last) */
}
Angles 90deg
#gradient9
{
background: -webkit-linear-gradient(90deg, green, blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(90deg, green, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(90deg, green, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(90deg, green, blue); /* Standard syntax (must be last) */
}
Angles 180deg
#gradient10
{
background: -webkit-linear-gradient(180deg, green, blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(180deg, green, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(180deg, green, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(180deg, green, blue); /* Standard syntax (must be last) */
}
Angles -90deg
#gradient11
{
background: -webkit-linear-gradient(-90deg, green, blue); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(-90deg, green, blue); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(-90deg, green, blue); /* For Firefox 3.6 to 15 */
background: linear-gradient(-90deg, green, blue); /* Standard syntax (must be last) */
}
- Radial Gradients (defined by their center)
To create a radial gradient you must also define at least two color stops. You can also specify the gradient’s center, shape (circle or ellipse) as well as its size. By default, center is center, shape is ellipse, and size is farthest-corner.
Radial Gradient – Shape Default
#gradient12
{
background: -webkit-radial-gradient(red, green, blue); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(red, green, blue); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(red, green, blue); /* For Firefox 3.6 to 15 */
background: radial-gradient(red, green, blue); /* Standard syntax (must be last) */
}
Radial Gradient – Shape Circle
#gradient13
{
background: -webkit-radial-gradient(circle, red, green, blue); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(circle, red, green, blue); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(circle, red, green, blue); /* For Firefox 3.6 to 15 */
background: radial-gradient(circle, red, green, blue); /* Standard syntax (must be last) */
}
Radial Gradient – Closest Side
#gradient14
{
background: -webkit-radial-gradient(60% 55%, closest-side,blue,green,yellow,red); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(60% 55%, closest-side,blue,green,yellow,red); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(60% 55%, closest-side,blue,green,yellow,red); /* For Firefox 3.6 to 15 */
background: radial-gradient(60% 55%, closest-side,blue,green,yellow,red); /* Standard syntax (must be last) */
}
Radial Gradient – Farthest Side
#gradient15
{
background: -webkit-radial-gradient(60% 55%, farthest-side,blue,green,yellow,red); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(60% 55%, farthest-side,blue,green,yellow,red); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(60% 55%, farthest-side,blue,green,yellow,red); /* For Firefox 3.6 to 15 */
background: radial-gradient(60% 55%, farthest-side,blue,green,yellow,red); /* Standard syntax (must be last) */
}
Radial Gradient – Closest Corner
#gradient16
{
background: -webkit-radial-gradient(60% 55%, closest-corner,blue,green,yellow,red); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(60% 55%, closest-corner,blue,green,yellow,red); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(60% 55%, closest-corner,blue,green,yellow,red); /* For Firefox 3.6 to 15 */
background: radial-gradient(60% 55%, closest-corner,blue,green,yellow,red); /* Standard syntax (must be last) */
}
Radial Gradient – Farthest Corner
#gradient17
{
background: -webkit-radial-gradient(60% 55%, farthest-corner,blue,green,yellow,red); /* Safari 5.1 to 6.0 */
background: -o-radial-gradient(60% 55%, farthest-corner,blue,green,yellow,red); /* For Opera 11.6 to 12.0 */
background: -moz-radial-gradient(60% 55%, farthest-corner,blue,green,yellow,red); /* For Firefox 3.6 to 15 */
background: radial-gradient(60% 55%, farthest-corner,blue,green,yellow,red); /* Standard syntax (must be last) */
}
Radial Gradient – Repeating
#gradient18
{
background: -webkit-repeating-radial-gradient(red, green 4%, yellow 10%, grey 15%); /* For Safari 5.1 to 6.0 */
background: -o-repeating-radial-gradient(red, green 4%, yellow 10%, grey 15%); /* For Opera 11.6 to 12.0 */
background: -moz-repeating-radial-gradient(red, green 4%, yellow 10%, grey 15%); /* For Firefox 3.6 to 15 */
background: repeating-radial-gradient(red, green 4%, yellow 10%, grey 15%); /* Standard syntax (must be last) */
}
Note: Internet Explorer 9 and earlier versions do not support gradients.
More articles
Building a Better Learning Experience: Why E-Learning Needs UX Thinking
In the world of online education, content is king — but without smart UX (User Experience) design, even the best content gets lost. Whether you’re training employees, educating customers, or…
Read article →
Build a Tribe, Not Just a Site: The Power of Custom Membership Platforms
In the wild digital rainforest, a loyal tribe is your greatest strength. For modern brands, building a custom membership website isn’t just about restricting content — it’s about cultivating community,…
Read article →
Digital Darwinism: Adapting Your Brand Strategy for a Jungle-Like Marketplace
In the digital jungle, survival doesn’t go to the strongest or the smartest — it goes to the most adaptable. At Intellecta, we call this phenomenon Digital Darwinism: the reality…
Read article →