In 2024, we can do this cross-browser, with no vendor prefixes!

p {
    background-image: linear-gradient(red, blue);
    color: transparent;
    background-clip: text;
}

Some things to note:

  • A lot of the old examples use -webkit-text-fill-color rather than color. The two are actually functionally identicial[1] (and both support transparent!), -webkit-text-fill-color just takes precidence. The reason this was used in old examples was because it provided a graceful fallback for non-webkit browsers --- any non-webkit browser that ignored the gradient or clip instructions would also ignore the -webkit-text-fill-color instruction, meaning that you wouldn't be left with transparent text on unsupported browsers. I guess this is a problem with this cross browser implementation, in that that we can't do a fallback like this, but it'll really only be a problem for really old browsers like IE11.
  • background-clip is now standards tracked and implemented in all browsers. However, it took Chrome a long time to support the text clip option on the non-vendor prefixed one, with this only coming in Chrome 120, released mid 2023! As such, using both background-clip: text (for e.g. Firefox) and -webkit-background-clip: text was the best solution until just very recently, and you might still need both unless you're only targeting ultra-modern browser versions.
Answer from toastrackengima on Stack Overflow
๐ŸŒ
CSS Gradient
cssgradient.io โ€บ blog โ€บ css-gradient-text
CSS Gradient Text โ€“ CSS Gradient
Add eye-catching gradient effects to your website text using pure CSS. Learn how to create vibrant, image-free text gradients with step-by-step syntax examples and tips.
Top answer
1 of 7
54

In 2024, we can do this cross-browser, with no vendor prefixes!

p {
    background-image: linear-gradient(red, blue);
    color: transparent;
    background-clip: text;
}

Some things to note:

  • A lot of the old examples use -webkit-text-fill-color rather than color. The two are actually functionally identicial[1] (and both support transparent!), -webkit-text-fill-color just takes precidence. The reason this was used in old examples was because it provided a graceful fallback for non-webkit browsers --- any non-webkit browser that ignored the gradient or clip instructions would also ignore the -webkit-text-fill-color instruction, meaning that you wouldn't be left with transparent text on unsupported browsers. I guess this is a problem with this cross browser implementation, in that that we can't do a fallback like this, but it'll really only be a problem for really old browsers like IE11.
  • background-clip is now standards tracked and implemented in all browsers. However, it took Chrome a long time to support the text clip option on the non-vendor prefixed one, with this only coming in Chrome 120, released mid 2023! As such, using both background-clip: text (for e.g. Firefox) and -webkit-background-clip: text was the best solution until just very recently, and you might still need both unless you're only targeting ultra-modern browser versions.
2 of 7
21

You can do it using CSS but it will only work in webkit browsers (Chrome and Safari):

p {
    background: linear-gradient(red, blue);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent;
}
<p>blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah</p>

Discussions

css - Gradient text color - Stack Overflow
Is there a generator , or an easy way to generate text like this but without having to define every letter So something like this: .rainbow { background-image: -webkit-gradient( linear, le... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to create a gradient text with each letter wrapped in a different <div>
Hmmm, the problem you have is you want to apply a gradual consistent visual style to multiple separate elements. You could do this with masking by doing the following: wrap the spans in a parent div; set the background of the parent div to the gradient color; set the mix-blend-mode on the text to color-dodge (I think) - maybe flick through them to find the right one; It's been a while since I did this so the details might be off but I know masking is the right approach to preserve a consistent gradients across multiple child elements without breaking your animation More on reddit.com
๐ŸŒ r/webdev
23
3
January 2, 2024
How to Create Gradient Text in React?
Itโ€™s simple css: https://codepen.io/leocampos/pen/pPwwNR More on reddit.com
๐ŸŒ r/reactjs
12
3
February 26, 2022
Is there a way to make text color be the inverse of the backgrounds it's on? Specifically if the background is a gradient?
You can accomplish this with CSS blend-mode. Check out this Codepen: https://codepen.io/trezy/pen/yLPmxwo More on reddit.com
๐ŸŒ r/webdev
7
6
March 10, 2022
๐ŸŒ
Colorffy
colorffy.com โ€บ text-gradient-generator
CSS Text Gradient Generator | Colorffy
Simply choose your desired colors, set the gradient direction (linear, radial, or conic), and watch your text come to life in the real-time preview. Once you've crafted the perfect effect, our tool instantly generates the clean, cross-browser compatible CSS code.
๐ŸŒ
Fossheim
fossheim.io โ€บ writing โ€บ posts โ€บ css-text-gradient
How to add a gradient overlay to text with CSS by Sarah L. Fossheim
We can do this by adding a background-color property to the text as well. .gradient-text { background-color: #f3ec78; background-image: linear-gradient(45deg, #f3ec78, #af4261); background-size: 100%; -webkit-background-clip: text; -moz-background-clip: text; -webkit-text-fill-color: transparent; -moz-text-fill-color: transparent; }
๐ŸŒ
Gradient Page
gradient.page โ€บ css โ€บ text-gradient
How to create Linear Text Gradients quickly in CSS & HTML
Learn how to create CSS text gradients quickly in CSS and HTML. This tutorial will show you how to create a gradient pattern with your text.
๐ŸŒ
CSS Portal
cssportal.com โ€บ css-text-gradient-generator
CSS Text Gradient Generator - CSS Portal
The CSS text gradient generator provides a user-friendly interface where you can customize various aspects of the text gradient, such as the colors, direction, and other gradient properties.
๐ŸŒ
CodyHouse
codyhouse.co โ€บ nuggets โ€บ text-gradients
Text Gradients in CSS | CodyHouse
November 24, 2020 - .text-gradient { /* ๐Ÿ‘‡ show a solid color in older browsers (e.g., IE11) */ color: darkblue; } /* ๐Ÿ‘‡ show the text gradient in modern browsers */ @supports (--css: variables) { .text-gradient { background: linear-gradient(to right, darkblue, darkorchid); color: transparent; -webkit-background-clip: text; background-clip: text; } }
Find elsewhere
๐ŸŒ
This Dot Labs
thisdot.co โ€บ blog โ€บ how-to-apply-a-gradient-effect-to-text-with-css
How to Apply a Gradient Effect to Text with CSS - This Dot Labs
February 16, 2023 - This concept involves us first applying the gradient to the entire text, then targeting the part on the text we dont wnat the gradient to affect by wrapping that part of the text with any tag of your choice.
๐ŸŒ
W3Schools
w3schools.com โ€บ css โ€บ css3_gradients.asp
CSS Gradients
The CSS gradient functions let you display smooth transitions between two or more colors within an element.
๐ŸŒ
Coding Dude
coding-dude.com โ€บ home โ€บ blog โ€บ creating gradient text with html and css
Creating Gradient Text with HTML and CSS - Coding Dude
April 2, 2023 - CSS is a powerful tool for creating gradient text. The linear-gradient() function is used to create linear gradients, and the radial-gradient() function is used to create radial gradients.
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ css โ€บ visual โ€บ gradient text
CSS - Gradient text - 30 seconds of code
September 10, 2024 - You use the linear-gradient() function to define the gradient colors and direction. Then, you have to apply it to the text using the -webkit-text-fill-color property with a value of transparent.
๐ŸŒ
CodePen
codepen.io โ€บ leocampos โ€บ pen โ€บ pPwwNR
Gradient text color
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset.
๐ŸŒ
TW Elements
tw-elements.com โ€บ docs โ€บ standard โ€บ extended โ€บ gradient-text
Tailwind CSS Gradient text - Free Examples & Tutorial
Use responsive gradient text with TW elements. This tutorial will explore how you can add gradient text without adding any custom styles.
๐ŸŒ
Amit Merchant
amitmerchant.com โ€บ animated-gradient-effect-in-css
Animated gradient text in CSS - Amit Merchant
February 28, 2023 - And the background property is set to the gradient effect which will be used as the basis for the animation. And thatโ€™s pretty much it. You can tweak the animation duration, timing function, and gradient effect to your liking.
๐ŸŒ
UnusedCSS
unused-css.com โ€บ blog โ€บ css-text-gradient
CSS Text Gradient | UnusedCSS
March 3, 2022 - A CSS gradient is a progression of two or more colors, in a specified manner and direction. The series of colors diffuse into each other smoothly at defined angles. Gradients are soothing visuals that provide a pleasant, aesthetic effect to ...
Top answer
1 of 7
86

I don't exactly know how the stop stuff works. But I've got a gradient text example. Maybe this will help you out!

_you can also add more colors to the gradient if you want or just select other colors from the color generator

.rainbow2 {
  background-image: linear-gradient(to right, #E0F8F7, #585858, #fff);
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}

.rainbow {
  background-image: linear-gradient(to right, #f22, #f2f, #22f, #2ff, #2f2, #ff2);
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}
<span class="rainbow">Rainbow text</span>
<br />
<span class="rainbow2">No rainbow text</span>

2 of 7
16

The way this effect works is very simple. The element is given a background which is the gradient. It goes from one color to another depending on the colors and color-stop percentages given for it.

For example, in rainbow text sample (note that I've converted the gradient into the standard syntax):

  • The gradient starts at color #f22 at 0% (that is the left edge of the element). First color is always assumed to start at 0% even though the percentage is not mentioned explicitly.
  • Between 0% to 14.25%, the color changes from #f22 to #f2f gradually. The percenatge is set at 14.25 because there are seven color changes and we are looking for equal splits.
  • At 14.25% (of the container's size), the color will exactly be #f2f as per the gradient specified.
  • Similarly the colors change from one to another depending on the bands specified by color stop percentages. Each band should be a step of 14.25%.

So, we end up getting a gradient like in the below snippet. Now this alone would mean the background applies to the entire element and not just the text.

.rainbow {
  background-image: linear-gradient(to right, #f22, #f2f 14.25%, #22f 28.5%, #2ff 42.75%, #2f2 57%, #2f2 71.25%, #ff2 85.5%, #f22);
  color: transparent;
}
<span class="rainbow">Rainbow text</span>

Since, the gradient needs to be applied only to the text and not to the element on the whole, we need to instruct the browser to clip the background from the areas outside the text. This is done by setting background-clip: text.

(Note that the background-clip: text is an experimental property and is not supported widely.)


Now if you want the text to have a simple 3 color gradient (that is, say from red - orange - brown), we just need to change the linear-gradient specification as follows:

  • First parameter is the direction of the gradient. If the color should be red at left side and brown at the right side then use the direction as to right. If it should be red at right and brown at left then give the direction as to left.
  • Next step is to define the colors of the gradient. Since our gradient should start as red on the left side, just specify red as the first color (percentage is assumed to be 0%).
  • Now, since we have two color changes (red - orange and orange - brown), the percentages must be set as 100 / 2 for equal splits. If equal splits are not required, we can assign the percentages as we wish.
  • So at 50% the color should be orange and then the final color would be brown. The position of the final color is always assumed to be at 100%.

Thus the gradient's specification should read as follows:

background-image: linear-gradient(to right, red, orange 50%, brown).

If we form the gradients using the above mentioned method and apply them to the element, we can get the required effect.

.red-orange-brown {
  background-image: linear-gradient(to right, red, orange 50%, brown);
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}
.green-yellowgreen-yellow-gold {
  background-image: linear-gradient(to right, green, yellowgreen 33%, yellow 66%, gold);
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
}
<span class="red-orange-brown">Red to Orange to Brown</span>

<br>

<span class="green-yellowgreen-yellow-gold">Green to Yellow-green to Yellow to Gold</span>

๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ how to create text gradient in css?
How to Create Text Gradient in CSS? - Scaler Topics
March 27, 2024 - Text gradients in CSS: A text gradient in CSS is a type of linear gradient for text styling in which the text is filled with colour. The text is coloured with a continuation from the start point to the endpoint.
๐ŸŒ
Reddit
reddit.com โ€บ r/webdev โ€บ how to create a gradient text with each letter wrapped in a different
r/webdev on Reddit: How to create a gradient text with each letter wrapped in a different <div>
January 2, 2024 -

So I am animating a text, for the sake of the animation I need the letters of let's say "Hello" to be divided each in a different <div>, the text though has to have a gradient effect to it.

I can't find a way to combine this two worlds, I didn't find anything online. How would someone approach this problem?

Top answer
1 of 5
5
Hmmm, the problem you have is you want to apply a gradual consistent visual style to multiple separate elements. You could do this with masking by doing the following: wrap the spans in a parent div; set the background of the parent div to the gradient color; set the mix-blend-mode on the text to color-dodge (I think) - maybe flick through them to find the right one; It's been a while since I did this so the details might be off but I know masking is the right approach to preserve a consistent gradients across multiple child elements without breaking your animation
2 of 5
3
Edit: this comment is not a solution. This comment is, although there may be simpler approaches too: https://www.reddit.com/r/webdev/s/8HHgYiUpkA The solution I posted the other day was totally unnecessary possibly necessary (although it did work) and I'm removing it I should've left it up! The following should also work: HTML H e l l o CSS .gradient-text { background-image: linear-gradient(90deg, red, blue); background-clip: text; color: transparent; } The reason the parent div gradient wasn't working is it was a block-level element so it stretched to fill the full width of its own parent container, meaning the gradient would be wider than the text, so you wouldn't have the full gradient showing. I made the parent a span so it is inline and thus no wider than its child elements, but you could also use width: fit-content; in the .gradient-text CSS selector if it is a block-level element such as a div.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ web templates โ€บ how-to-create-linear-gradient-text-using-html-and-css
How to create linear gradient text using HTML and CSS ? - GeeksforGeeks
July 15, 2025 - Please refer linear-gradient() method to create a gradient background and then use webkit properties to overlay that background with our text. Example: In the following section, the text used for demonstration is wrapped inside the h1 tag.
๐ŸŒ
CSS gradient text
cssgradienttext.com
CSS gradient text | free online gradient text generator
Enhance your web projects with our CSS Gradient Text Generator. Easily create stunning gradient texts, adjust colors and angles, and now with a single click, copy either CSS or HTML styled code directly into your project.