You can do it in CSS, but there isn't much support in browsers other than modern versions of Chrome, Safari and Opera at the moment. Firefox currently only supports SVG masks. See the Caniuse results for more information.

EDIT: all browsers except IE now support all mask- properties mentioned here.

CSS:

p {
    color: red;
    -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, 
    from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}

The trick is to specify a mask that is itself a gradient that ends as invisible (thru alpha value)

See a demo with a solid background, but you can change this to whatever you want.

DEMO

Notice also that all the usual image properties are available for mask-image

p  {
  color: red;
  font-size: 30px;
  -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,1), rgba(0,0,0,0)), linear-gradient(to right, rgba(0,0,0,1), rgba(0,0,0,0));
  -webkit-mask-size: 100% 50%;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: left top, left bottom;
  }

div {
    background-color: lightblue;
}
<div><p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p></div>

Now, another approach is available, that is supported by Chrome, Firefox, Safari and Opera.

The idea is to use

mix-blend-mode: hard-light;

that gives transparency if the color is gray. Then, a grey overlay on the element creates the transparency

div {
  background-color: lightblue;
}

p {
  color: red;
  overflow: hidden;
  position: relative;
  width: 200px;
  mix-blend-mode: hard-light;
}

p::after {
  position: absolute;
  content: "";
  left: 0px;
  top: 0px;
  height: 100%;
  width: 100%;
  background: linear-gradient(transparent, gray);
  pointer-events: none;
}
<div><p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p></div>

Answer from vals on Stack Overflow
Top answer
1 of 5
158

You can do it in CSS, but there isn't much support in browsers other than modern versions of Chrome, Safari and Opera at the moment. Firefox currently only supports SVG masks. See the Caniuse results for more information.

EDIT: all browsers except IE now support all mask- properties mentioned here.

CSS:

p {
    color: red;
    -webkit-mask-image: -webkit-gradient(linear, left top, left bottom, 
    from(rgba(0,0,0,1)), to(rgba(0,0,0,0)));
}

The trick is to specify a mask that is itself a gradient that ends as invisible (thru alpha value)

See a demo with a solid background, but you can change this to whatever you want.

DEMO

Notice also that all the usual image properties are available for mask-image

p  {
  color: red;
  font-size: 30px;
  -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,1), rgba(0,0,0,0)), linear-gradient(to right, rgba(0,0,0,1), rgba(0,0,0,0));
  -webkit-mask-size: 100% 50%;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: left top, left bottom;
  }

div {
    background-color: lightblue;
}
<div><p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p></div>

Now, another approach is available, that is supported by Chrome, Firefox, Safari and Opera.

The idea is to use

mix-blend-mode: hard-light;

that gives transparency if the color is gray. Then, a grey overlay on the element creates the transparency

div {
  background-color: lightblue;
}

p {
  color: red;
  overflow: hidden;
  position: relative;
  width: 200px;
  mix-blend-mode: hard-light;
}

p::after {
  position: absolute;
  content: "";
  left: 0px;
  top: 0px;
  height: 100%;
  width: 100%;
  background: linear-gradient(transparent, gray);
  pointer-events: none;
}
<div><p>text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text </p></div>

2 of 5
9

Except using css mask answered by @vals, you can also use transparency gradient background and set background-clip to text.

Create proper gradient:

background: linear-gradient(to bottom, rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%);

Then clip the backgroud with text:

background-clip: text;
color: transparent;

Demo

https://jsfiddle.net/simonmysun/2h61Ljbn/4/

Tested under Chrome 75 under Windows 10.

Supported platforms:

  • https://caniuse.com/mdn-css_properties_background-clip_text
  • https://caniuse.com/css-gradients
🌐
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 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
Gradient with background color opacity and custom percentage stop
can you help me with this background: linear-gradient(0deg, rgba(0, 0, 0, 0.50) 0%, rgba(0, 0, 0, 0.50) 100%), #363A43; More on github.com
🌐 github.com
4
1
February 28, 2023
Wrong gradient behavior with opacity | Figma Forum
The illusion is caused by a sudden stop of the linear gradient, causing our eyes/brain to amplify the edge’s contrast. This can be reduced by changing to an easing gradient. ... With those plugins, you can compose overlaid gradients without the “cross” illusion in the corner: ... We’re interested in what’s happening in the middle, so 50% of the way through the gradient. Figma shows 50% of color B, at 50% opacity... More on forum.figma.com
🌐 forum.figma.com
March 20, 2024
css - opacity on linear gradient background-image - Stack Overflow
how can I set an opacity value, for example opacity: 0.6 on a linear-gradient background-image? background-image: linear-gradient(to left, #00497a -26.48%,#003366 73.52%); Thanks! More on stackoverflow.com
🌐 stackoverflow.com
🌐
Ahmad Shadeed
ishadeed.com › snippet › fake-opacity-gradient
How to Fake Opacity With a CSS Background
I need a dynamic way to fake an opacity for the pattern image. I shouldn’t use an additional HTML element for this job. It should be responsive. To implement that, we can use multiple CSS gradients. Here is how I did it: :root { --oval-w: 50%; --oval-h: 70%; --base-color: rgba(194, 236, 231, 0.8); --pattern: url("hero-bg.svg"); } .hero { min-height: 400px; background: linear-gradient(var(--base-color), var(--base-color)), radial-gradient(#c2ece7 25%, transparent) center/50% 90% no-repeat, var(--pattern) center/cover no-repeat; }
🌐
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 › Reference › Values › gradient › linear-gradient
linear-gradient() - CSS - MDN Web Docs - Mozilla
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), transparent 70.71%), linear-gradient(127deg, rgb(0 255 0 / 0.8), transparent 70.71%), linear-gradient(336deg, rgb(0 0 255 / 0.8), transparent 70.71%);
Find elsewhere
🌐
CodePen
codepen.io › mrbird › embed › JJmgJY
CodePen Embed - linear-gradient(opacity)
div { height: 200px; width: 350px; background: linear-gradient(to right, rgba(169,208,113,0),rgba(136,173,215,1)); }
🌐
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 - The gradient transitions from red (hue 0) to blue (hue 240) with 50% saturation and lightness, while the alpha value (0.5) controls the transparency level. Example: Illustration of transparency with Linear Gradient in CSS Using HSLA Colors in CSS.
🌐
Oreillymedia
oreillymedia.github.io › svg-essentials-examples › ch08 › stop_opacity.html
Linear Gradient using stop-opacity
<svg width="250" height="150" viewBox="0 0 250 150" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <defs> <linearGradient id="three_opacity_stops"> <stop offset="0%" style="stop-color: #906; stop-opacity: 1.0"/> <stop offset="50%" style="stop-color: #906; stop-opacity: 0.3"/> <stop offset="100%" style="stop-color: #906; stop-opacity: 0.10"/> </linearGradient> </defs> <rect x="20" y="20" width="200" height="100" style="fill: url(#three_opacity_stops); stroke: black;"/> </svg>
🌐
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 - 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.
Top answer
1 of 1
4
Let’s label the gradient: Color A +---------+ Color B100% opacity +---------+ 0% opacityWe’re interested in what’s happening in the middle, so 50% of the way through the gradient.Figma shows 50% of color B, at 50% opacity.The browser shows 0% of color B, at 50% opacity.I would lean into the direction of Figma rendering it correctly. It shows all the intermediate colors, so the orange color “leaks” into the gradient from the right side. Makes sense to me.On the other hand, browsers use the alpha-premultiplied color space. As a result, it doesn’t matter what color you set on the other end - all hues will render exactly the same. To me, this is a weird behavior, because the browser ignores the color of the end stop.I assume this creates problems when handing off the designs to developers. If they use the CSS as-is, they might not have the same result as shown on designs.Possible solutions:Manually add the middle gradient stop, and set it to orange at 50% opacity.If you don’t want Figma’s effect, use the same colors on A and B ends of the gradient, and only set different opacities.Tell your developers to use a solid gradient, with a mask that’s another gradient. (See below)Convince Figma to automatically calculate the intermediate gradient stops, so Figma’s rendering can be replicated in browsers that render it “wrong”. Tagging @y_toku.Convince W3C to allow disabling alpha-premultiplied behaviors, which currently completely ignore the color stops.Figma’s rendering:CSS (will cause this issue):background: linear-gradient(to right, red, rgba(0, 0, 255, 0));CSS (fixed):background: linear-gradient(to right, red, blue);mask-image: linear-gradient(to right, white, transparent);
🌐
DEV Community
dev.to › lecopsportif › create-a-gradient-opacity-in-css-29ni
Create a gradient opacity in CSS? - DEV Community
December 26, 2017 - For example, you can use the following code to create a gradient that fades from a solid blue color to a transparent blue color: #map { height: 400px; background-image: linear-gradient(to bottom, rgba(64, 92, 177, 1), rgba(64, 92, 177, 0)); }
🌐
Lynneslair
lynneslair.com › opacity
SVG: Opacity, Gradients and Filters – Lynne's Lair
It is possible to smoothly vary a colour or an opacity in a fill or stroke using a gradient. There are two types of gradients, linear and radial. A linear gradient changes colour/opacity in a straight line from a point whilst colour/opacity changes radiate outwards from a point with a radial ...
🌐
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
🌐
GitHub
github.com › react-native-linear-gradient › react-native-linear-gradient › issues › 247
react-native-linear-gradient with Opacity · Issue #247 · react-native-linear-gradient/react-native-linear-gradient
December 18, 2017 - render() { return ( <ImageBackground style={styles.container} source={require('./assets/background_login.jpg')}> <LinearGradient colors={['rgba(156, 68, 249,0.5)', 'rgba(114, 110, 248,0.5)', 'rgb(79, 206, 249)']} style={styles.contentContainer} ...
Author   OmarACY
🌐
Webflow
discourse.webflow.com › design help › layout & design
Linear Gradient Transparency not working? - Layout & Design - Forum | Webflow
August 23, 2021 - Hi folks, Please help. It’s on the Xmas Charm Page. I can’t figure out why the linear gradient isn’t transparent. On the linear-gradient panel, the white is set to 100% Opacity, but displays full strength? Ultimately I …