MOCKSTACKS
EN
Questions And Answers

More Tutorials









CSS Background gradient

Gradients are new image types, added in CSS3. As an image, gradients are set with the background-image property, or the background shorthand.

There are two types of gradient functions, linear and radial. Each type has a non-repeating variant and a repeating variant:

  • linear-gradient()
  • repeating-linear-gradient()
  • radial-gradient()
  • repeating-radial-gradient()

linear-gradient()

A linear-gradient has the following syntax

background: linear-gradient( <direction>?, <color-stop-1>, <color-stop-2>, ...);

For example, this creates a linear gradient that starts from the right and transitions from red to blue

.linear-gradient {
background: linear-gradient(to left, red, blue ); 
}



You can create a diagonal gradient by declaring both a horizontal and vertical starting position.

.diagonal-linear-gradient {
background: linear-gradient( to left top, red, yellow 10% );
}



It is possible to specify any number of color stops in a gradient by separating them with commas. The following examples will create a gradient with 8 color stops

.linear-gradient-rainbow {
background: linear-gradient(to left, red, orange, yellow, green, blue, indigo, violet );
}


.radial-gradient-simple

.radial-gradient-simple {
background: radial-gradient(red, blue );
}


Note that HEX, RGB, RGBa, HSL, and HSLa color codes may be used instead of color names. Color names were used for the sake of illustration.




Conclusion

In this page (written and validated by ) you learned about CSS background Gradient . What's Next? If you are interested in completing CSS tutorial, your next topic will be learning about: CSS background image.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.