Linear Gradient - Transparency

CSS3 gradients also support transparency, which can be used to create fading effects. To add transparency, use the rgba() function to define the color stops. The last parameter in the rgba() function can be a value from 0 to 1, which defines the transparency of the color: 0 indicates full transparency, while 1 indicates full color (no transparency). The following example shows a linear gradient that starts at the left as fully transparent, transitioning to full color red at the right:

HTML file: Displayed by browser:
<style>
#grad1 {
    height: 200px;
    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) */
}
</style>
<body>
<div id="grad1"><p style="text-align:left;"><==== Fully transparent at the left</p>
<p style="text-align:right;">Full color at the right ====></p></div>
</body>

<==== Fully transparent at the left

Full color at the right ====>

Note: Internet Explorer 9 and earlier versions do not support gradients.

Back button Table of Contents Next button