Keep in mind that a CSS gradient is actually an image value, not a color value as some might expect. Therefore, it corresponds to background-image specifically, and not background-color, or the entire background shorthand.

Essentially, what you're really trying to do is layering two background images: a bitmap image over a gradient. To do this, you specify both of them in the same declaration, separating them using a comma. Specify the image first, followed by the gradient. If you specify a background color, that color will always be painted underneath the bottom-most image, which means a gradient will cover it just fine, and it will work even in the case of a fallback.

Because you're including vendor prefixes, you will need to do this once for every prefix, once for prefixless, and once for fallback (without the gradient). To avoid having to repeat the other values, use the longhand properties1 instead of the background shorthand:

#mydiv .isawesome { 
    background-color: #B1B8BD;
    background-position: 0 0;
    background-repeat: no-repeat;

    /* Fallback */
    background-image: url('../images/sidebar_angle.png');

    /* CSS gradients */
    background-image: url('../images/sidebar_angle.png'), 
                      -moz-linear-gradient(top, #ADB2B6 0%, #ABAEB3 100%);
    background-image: url('../images/sidebar_angle.png'), 
                      -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ADB2B6), color-stop(100%, #ABAEB3));
    background-image: url('../images/sidebar_angle.png'), 
                      linear-gradient(to bottom, #ADB2B6, #ABAEB3);

    /* IE */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ADB2B6', endColorstr='#ABAEB3', GradientType=0);
}

Unfortunately this doesn't work correctly in IE as it uses filter for the gradient, which it always paints over the background.

To work around IE's issue you can place the filter and the background image in separate elements. That would obviate the power of CSS3 multiple backgrounds, though, since you can just do layering for all browsers, but that's a trade-off you'll have to make. If you don't need to support versions of IE that don't implement standardized CSS gradients, you have nothing to worry about.


1 Technically, the background-position and background-repeat declarations apply to both layers here because the gaps are filled in by repeating the values instead of clamped, but since background-position is its initial value and background-repeat doesn't matter for a gradient covering the entire element, it doesn't matter too much. The details of how layered background declarations are handled can be found here.

Answer from BoltClock on Stack Overflow
Top answer
1 of 5
50

Keep in mind that a CSS gradient is actually an image value, not a color value as some might expect. Therefore, it corresponds to background-image specifically, and not background-color, or the entire background shorthand.

Essentially, what you're really trying to do is layering two background images: a bitmap image over a gradient. To do this, you specify both of them in the same declaration, separating them using a comma. Specify the image first, followed by the gradient. If you specify a background color, that color will always be painted underneath the bottom-most image, which means a gradient will cover it just fine, and it will work even in the case of a fallback.

Because you're including vendor prefixes, you will need to do this once for every prefix, once for prefixless, and once for fallback (without the gradient). To avoid having to repeat the other values, use the longhand properties1 instead of the background shorthand:

#mydiv .isawesome { 
    background-color: #B1B8BD;
    background-position: 0 0;
    background-repeat: no-repeat;

    /* Fallback */
    background-image: url('../images/sidebar_angle.png');

    /* CSS gradients */
    background-image: url('../images/sidebar_angle.png'), 
                      -moz-linear-gradient(top, #ADB2B6 0%, #ABAEB3 100%);
    background-image: url('../images/sidebar_angle.png'), 
                      -webkit-gradient(linear, left top, left bottom, color-stop(0%, #ADB2B6), color-stop(100%, #ABAEB3));
    background-image: url('../images/sidebar_angle.png'), 
                      linear-gradient(to bottom, #ADB2B6, #ABAEB3);

    /* IE */
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ADB2B6', endColorstr='#ABAEB3', GradientType=0);
}

Unfortunately this doesn't work correctly in IE as it uses filter for the gradient, which it always paints over the background.

To work around IE's issue you can place the filter and the background image in separate elements. That would obviate the power of CSS3 multiple backgrounds, though, since you can just do layering for all browsers, but that's a trade-off you'll have to make. If you don't need to support versions of IE that don't implement standardized CSS gradients, you have nothing to worry about.


1 Technically, the background-position and background-repeat declarations apply to both layers here because the gaps are filled in by repeating the values instead of clamped, but since background-position is its initial value and background-repeat doesn't matter for a gradient covering the entire element, it doesn't matter too much. The details of how layered background declarations are handled can be found here.

2 of 5
41

You can use Transparency and gradients. Gradients support transparency. You can use this, for example, when stacking multiple backgrounds, to create fading effects on background images.

background: linear-gradient(to right, rgba(255,255,255,0) 20%,
              rgba(255,255,255,1)), url(http://foo.com/image.jpg);

🌐
W3Schools
w3schools.com › css › tryit.asp
Linear Gradient - with transparency
The W3Schools online code editor allows you to edit code and view the result in your browser
Discussions

How to make a transparent gradient over an image?
Kalidh Mohamed is having issues with: Here is the code snipper.. .main-header { padding-top: 170px; height: 850px; background: url("../img/mountains.jpg") no-repeat ce... More on teamtreehouse.com
🌐 teamtreehouse.com
3
October 5, 2015
How to make a CSS border gradient with transparent background?
Hi there, is it possible to create a border gradient with a border-radius and a transparent background? This is a good tutorial to create a border gradient including border-radius. However it is not possible to set a transparent background. Is there any workaround to use a border gradient with ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
November 17, 2022
How can I combine a horizontal color gradient with a vertical opacity gradient in CSS3?
You put the opaque gradient, and you fake the transparency on top by making a gradient from transparent to background-color. background-image: linear-gradient(0deg, transparent 0%, white 100%), linear-gradient(90deg, #e89005 0%, #ec7505 33%, #d84a05 66%, #f42b03 100%); Replace white by the background color you need. More on reddit.com
🌐 r/webdev
3
1
June 1, 2022
Is it possible to use css to make a background image "fade" or gradient the bottom portion to transparent so that a background color shows? - Stack Overflow
MarcinJuraszek - Just the opposite of that. I want a solid background color, and an image that will have a css generated gradient to transparency at the bottom portion. More on stackoverflow.com
🌐 stackoverflow.com
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Images › Using_gradients
Using CSS gradients - CSS | MDN
This example overlaps three ... either that the colors of the gradients on the top of the stack are partially transparent or use the background-blend-mode CSS property....
🌐
Polypane
polypane.app › blog › my-take-on-fading-content-using-transparent-gradients-in-css
My take on fading content using transparent gradients in CSS | Polypane
January 19, 2024 - When using background-clip: text you want to combine it with color: transparent. Lastly to make that text fade, we're going to set the background to a linear gradient that fades from our text color (white) to transparent.
🌐
GeeksforGeeks
geeksforgeeks.org › css › how-to-set-transparency-with-linear-gradient-in-css
How to Set Transparency with Linear Gradient in CSS ? - GeeksforGeeks
July 23, 2025 - In this approach, first create a centered box with a linear gradient background using HSLA colors, which allows for transparency. The gradient transitions from red (hue 0) to blue (hue 240) with 50% saturation and lightness, while the alpha ...
Find elsewhere
🌐
CodePen
codepen.io › yochans › pen › ZEJNvRd
CSS | Transparent gradient in the image
<div class="container"> <img src="https://1-notes.com/wp-content/uploads/2020/06/quality-50-1024x682.jpg"> </div> <p><a href="https://1-notes.com/css-transparent-gradient-in-the-image/" target="_blank" rel="noopener">CSS | Transparent gradient in the image | ONE NOTES</a></p> ... body { padding: 0; margin: 10px; } .container { position: relative; max-width: 100%; width: 300px; height: 200px; } .container::after { content: ''; position: absolute; top: 0; left: 0; width: 300px; height: 200px; background-image: linear-gradient(180deg, transparent 0 30%, #FFF 70% 100%); } .container img { width: 100%; }
🌐
SheCodes
shecodes.io › athena › 3199-setting-background-opacity-with-linear-gradients-in-css
[CSS] - Setting Background Opacity with Linear Gradients in | SheCodes
Learn how to use CSS and the rgba function to set a linear gradient background opacity with an example code. ... I have several images in html. I want to target each one in CSS.
🌐
W3Schools
w3schools.com › css › css3_gradients.asp
CSS Gradients
The CSS linear-gradient() function creates a linear gradient. A linear gradient defines a color transition that goes in a straight line, it can go down, up, to left, to right, or diagonally. A linear gradient requires 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. background-image: linear-gradient(direction, color-stop1, color-stop2, ...);
🌐
GitHub
github.com › tailwindlabs › tailwindcss › discussions › 3433
Applying background opacity to a gradient background · tailwindlabs/tailwindcss · Discussion #3433
I often find myself in the same scenario so I found a workaround to get the effect you want. Basically, since the .bg-opacity has no effects on gradients (as well as CSS variables) we can use the regular .opacity combined with some .absolute to get the effect to work.
Author   tailwindlabs
🌐
YouTube
m.youtube.com › watch
How to add CSS Gradient Color Overlay on an Image ...
Share your videos with friends, family, and the world
Published   October 26, 2020
🌐
Reddit
reddit.com › r/webdev › how can i combine a horizontal color gradient with a vertical opacity gradient in css3?
r/webdev on Reddit: How can I combine a horizontal color gradient with a vertical opacity gradient in CSS3?
June 1, 2022 -

For one of my <div> elements, I have the following CSS for a horizonal color gradient:

background: linear-gradient(90deg, #e89005 0%, #ec7505 33%, #d84a05 66%, #f42b03 100%);

Now I want to add a linear vertical opacity gradient on top of this. How would I go about adding a second one?

(as per rule requirements, the context is that I am trying to build a website for my portfolio to get hired, and I tried googling how to add multiple gradients to one block level element in CSS. I also googled how to add opacity gradient with color, but only got results on things like rgba which does it in the same direction.)

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › gradient › linear-gradient
linear-gradient() - CSS | MDN
The linear-gradient() CSS function creates an image consisting of a progressive transition between two or more colors along a straight line. Its result is an object of the <gradient> data type, which is a special kind of <image>. ... background: linear-gradient(217deg, rgb(255 0 0 / 0.8), ...
Top answer
1 of 4
13

It is possible - in CSS3 you can set multiple values for background

body {
    background: #837960 url("https://i.sstatic.net/MUsp6.jpg") 0 0 no-repeat;

    background: -moz-linear-gradient(top, rgba(255,255,255,0) 0%, rgba(130,91,0,1) 100%);   /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,255,255,0)), color-stop(100%,rgba(130,91,0,1))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* IE10+ */
    background: linear-gradient(to bottom, rgba(255,255,255,0) 0%,rgba(130,91,0,1) 100%); /* W3C */
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#00ffffff', endColorstr='#825b00',GradientType=0 ); /* IE6-9 */
}

However, it will work only in modern browser that supports CSS3

(code generated via http://www.colorzilla.com/gradient-editor/)

2 of 4
12

Yes it's possible with CSS using the linear-gradient() function with multiple background images:

body {
  background-color: #837960;
  background-image: linear-gradient(
    to bottom, transparent, #837960
  ), url("Images/background.jpg");
  background-repeat: no-repeat;
}

Specify the gradient as the first image so it gets stacked on top, and use it to fade from transparent at the top to the opaque background-color at the bottom. This will give the illusion the image underneath is fading into the background without requiring alpha-transparency on the image itself.

🌐
Reddit
reddit.com › r/webdev › how to fix transparent border going past gradient background image
r/webdev on Reddit: How to fix transparent border going past gradient background image
August 18, 2024 -

I currently have a div with a gradient as a background image.

edges are different color

However, the problem I get is that the transparent border has some weird issue which is caused by the fact that the background image doesn't cover the area that the border does. I can't really find the solution to this anywhere.

This is currently what I have:

<div className="flex items-center justify-center gap-2 bg-grad rounded-full px-3 py-20 border-[3px] border-white/30">
    <p className="text-xl font-semibold text-white">Our Mission</p>
    <Image src="/rocket_launch.svg" alt="" width={10} height={10}/>
</div>

with .bg-grad defined as:

.bg-grad {
    background-image: linear-gradient(90deg, #FFB74A 0%, #FF4AA1 45%, #6F2BFF 100%);
  }
🌐
SheCodes
shecodes.io › athena › 3201-how-to-set-transparency-with-linear-gradient-in-css
[CSS] - How to Set Transparency with Linear Gradient in CSS | SheCodes
Discover how to use linear gradient and rgba to set the transparency of an element in CSS. ... I have several images in html. I want to target each one in CSS. How do i do this please? CSS HTML images class selectors id selectors styling ... How do you change how a website is display on a desktop PC versus a mobile device since the screen size is different? Responsive Design media queries CSS mobile devices desktop devices ... i made a container for my text with a background ...
🌐
vincoding
vincoding.com › css-transparent-gradient-overlay-image
CSS Transparent Gradient Overlay on an Image | vincoding
August 25, 2017 - This makes the overlay color appear to fade-in down the image. <style> .bgclass { background: linear-gradient(rgba(0,130,170,0),rgba(0,130,170,1)), url('/path/image.jpg'); } </style> There are many other gradient variations that you can use for some cool and useful effects on your images.
🌐
Squarespace Forum
forum.squarespace.com › home › customize with code › add a transparent gradient overlay to individual sections?
Add a transparent gradient overlay to individual sections? - Customize with code - Squarespace Forum
November 17, 2021 - Site URL: https://shuvamkabir.net I'm attempting to add a white gradient above my background images. My first thought is to add an additional element that serves as an intermediate layer. I've tried the following, which I copied from here : [data-section-id="xxxxxxxxxxxxxxx"]{ .section-background...