Yes, it is.

h1 {
  font-size: 72px;
   background: -webkit-linear-gradient(left, red , yellow);
   background: -o-linear-gradient(right, red, yellow);
   background: -moz-linear-gradient(right, red, yellow);
   background: linear-gradient(to right, red , yellow); 
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
<h1>Hello World</h1>

Example using React and styled-components:

const ColorText = styled.h1 `
  font-size: 72px;
  background: linear-gradient(to right, red , yellow); 
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
`;

const App = () => (
  <ColorText>Colorful Text</ColorText>
);

ReactDOM.createRoot(
  document.getElementById("root")
).render(<App/>);
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.development.js"></script>
<script crossorigin src="//unpkg.com/styled-components/dist/styled-components.min.js"></script>

Answer from kind user on Stack Overflow
🌐
CSS Gradient
cssgradient.io › blog › css-gradient-text
CSS Gradient Text – CSS Gradient
You can define the linear gradient angle in the code with a keyword or number and unit. With a keyword, you would use variations of to bottom, to top, to left, and to right to determine where the line should move to from the starting point.
🌐
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.
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>

🌐
Fossheim
fossheim.io › writing › posts › css-text-gradient
How to add a gradient overlay to text with CSS by Sarah L. Fossheim
An intro tutorial on how to add gradients to text with CSS, including examples and tips for scalability.
🌐
Hadrysmateusz
hadrysmateusz.com › blog › gradient-text
Gradient text in CSS - Mateusz Hadryś - Blog
What might surprise you — especially if you have prior experience with design tools — is that you can’t set a gradient as the text color directly. For example color: linear-gradient(yellow, red) won’t work. But gradient text can be achieved in CSS, it just requires a few extra steps.
🌐
CodePen
codepen.io › leocampos › pen › pPwwNR
Gradient text color
Minimize CSS Editor · Fold All · Unfold All · $font: 'Poppins', sans-serif; ::selection { background-color: #C3CFE2; } body { width: 100%; height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(to right, #FDFBFB, #EBEDEE 70%); } .text { text-transform: uppercase; background: linear-gradient(to right, #30CFD0 0%, #330867 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font: { size: 20vw; family: $font; }; } !
Find elsewhere
🌐
CSS-Tricks
css-tricks.com › snippets › css › gradient-text
Gradient Text | CSS-Tricks
December 19, 2012 - This is not “webkit only” now. “Opera” taken this prefix too, but don’t working… ... Good work… Keep goiing…. ... font-size:50px; background: -webkit-linear-gradient(#fff, #FC3,#FC3,#fff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
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>

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › gradient › linear-gradient
linear-gradient() - CSS - MDN Web Docs - Mozilla
The values to top, to bottom, to left, and to right are equivalent to the angles 0deg, 180deg, 270deg, and 90deg, respectively. The other values are translated into an angle. ... The gradient line's angle of direction. A value of 0deg is equivalent to to top; increasing values rotate clockwise ...
🌐
CSS Portal
cssportal.com › css-text-gradient-generator
CSS Text Gradient Generator - CSS Portal
A fun little generator...this online tool will create CSS Text Gradients. If you want add a bit of color to your headings or text, then just use this generator to create the CSS code that can then be used in your webpages.
🌐
SitePoint
sitepoint.com › blog › css › quick tip: how to add gradient effects and patterns to text
Quick Tip: How to Add Gradient Effects and Patterns to Text — SitePoint
April 6, 2024 - color: transparent; background-clip: text; background: linear-gradient(to right, #3b82f6, #c084fc, #db2777);
🌐
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 tutorial also assumes that ... of CSS and its properties like background, and background-color. Before we start creating gradient effect, let's understand a few concepts. Gradients let you display smooth transitions between two or more specified colors. You can read more about Gradient here. Perhaps the most common and useful type of gradient is the linear-gradient(). The gradients “axis” can go from left-to-right, top-to-bottom, ...
🌐
CSS Gradient
cssgradient.io
CSS Gradient – Generator, Maker, and Background
As a free CSS gradient generator tool, this website lets you create a colorful gradient background for your website, blog, or social media profile.
🌐
Delasign
delasign.com › blog › reactjs-gradient-text-css
How to apply a Gradient to Text in CSS
March 17, 2024 - Use the background, -webkit-background-clip and -webkit-text-fill-color CSS properties. Open Source code included. ... We recommend that you clone our Open Source React-Redux Starter Project, checking out the main branch and apply the code found ...
🌐
Design2Tailwind
design2tailwind.com › blog › tailwindcss-gradient-text
How to do gradient text with Tailwind CSS
August 29, 2022 - <h1 class="bg-gradient-to-r ... to work with gradients in Tailwind but to break it down: bg-gradient-to-r creates the gradient and makes it from left to right · from-blue-600 sets our starting color, which will go on ...
🌐
Medium
medium.com › design-bootcamp › gradient-text-in-css-609068d3f953
Gradient text in CSS. A simple technique for making… | by Mateusz Hadryś | Bootcamp | Medium
May 15, 2022 - ... By default the gradient will go from top to bottom, but we can also specify a direction. If you want a horizontal gradient, to right will do the trick, but a slight angle like 60deg looks more natural.
🌐
Gradient Page
gradient.page › css › text-gradient
How to create Linear Text Gradients quickly in CSS & HTML
Use our free CSS Linear Text Gradient Generator here: linear-gradient(to top left,#ff75c3,#ffa647,#ffe83f,#9fff5b,#70e2ff,#cd93ff) Hello World! h1 { display: inline-block; font-size: 48px; line-height: 1; font-weight: black; background: linear-gradient(to top left,#ff75c3,#ffa647,#ffe83f,#9fff5b,#70e2ff,#cd93ff) -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
🌐
W3Schools
w3schools.in › css3 › gradient-text
How to Create CSS Text Gradient - W3Schools
The -webkit-background-clip: text ... should start at the bottom of the text and end at the top. You can also use other keywords to set the gradient's direction, such as to left, to right......
🌐
Scaler
scaler.com › home › topics › how to create text gradient in css?
How to Create Text Gradient in CSS? - Scaler Topics
March 27, 2024 - We can combine these directional keywords, for instance - to the top right or to the bottom left (usually to create a diagonal line). The number and unit pairings can also be used to decide the angle and direction of the line. ... Let us look at an example for direction, for more clarity and better understanding. ... We will need at least two colours for the gradient to transition between to create the simplest sort of text gradients in CSS.