Gradient text is one of those effects that looks complicated when you first see it, but the actual implementation can be surprisingly simple. You do not need Photoshop, an image editor, JavaScript, or an image file.
With a few lines of CSS, you can turn an ordinary heading into text that smoothly transitions between multiple colors.
The important part is understanding what is actually happening. CSS does not have a normal gradient-text property. Instead, you create a gradient as a background and then clip that background to the shape of the text. The background-clip: text technique is widely supported, although you should still provide a readable fallback and test the browsers you support. (MDN Web Docs)
Here is the practical approach I use.
1. The basic CSS technique
Start with a normal HTML heading:
<h1 class="gradient-text">Build Better Websites</h1>
Then apply the gradient:
.gradient-text {
background: linear-gradient(90deg, #ff6a00, #ee0979);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
That is essentially the entire technique.
The linear-gradient() function creates a smooth transition between two or more colors. You can control its direction and add as many color stops as you need. (MDN Web Docs)
The important part is this:
background-clip: text;
It tells the browser to paint the background only inside the foreground text.
Then:
color: transparent;
makes the normal text color transparent so the gradient underneath becomes visible.
For broader practical compatibility, you will often see:
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
used alongside the standard declaration. MDN documents this technique and specifically notes the widespread browser implementation of the prefixed approach. (MDN Web Docs)
2. Why gradient text works this way
A common mistake is to look for something like:
color: linear-gradient(red, blue);
That does not work.
linear-gradient() produces a CSS gradient that behaves as an image, not as a <color> value. Therefore, you cannot directly put it into the color property. (MDN Web Docs)
Instead, think of the effect as three steps:
- Create a gradient.
- Put the gradient on the element’s background.
- Clip that background to the text.
Visually, the browser is doing something similar to this:
Gradient background
┌─────────────────────────────┐
│ RED → ORANGE → PURPLE → BLUE│
└─────────────────────────────┘
↓
Clip to the letters
↓
Gradient appears
inside the text
Once you understand that, gradient text becomes much easier to customize.
3. Choosing the right gradient
The CSS is easy. Choosing colors that actually look good is where many implementations go wrong.
A technically correct gradient can still make a website look amateurish.
For example:
background: linear-gradient(
90deg,
red,
yellow,
green,
blue,
purple
);
This works, but using five or six unrelated colors usually creates visual noise.
For most website headings, I prefer two or three colors.
For example:
background: linear-gradient(
90deg,
#6366f1,
#8b5cf6,
#ec4899
);
Or a simpler two-color version:
background: linear-gradient(
90deg,
#2563eb,
#9333ea
);
You can also use CSS angles:
background: linear-gradient(135deg, #06b6d4, #8b5cf6);
The angle controls the direction of the transition. MDN documents both directional keywords and degree-based gradients. (MDN Web Docs)
My practical rule
If the gradient is the main visual element, keep the rest of the design relatively quiet.
A gradient heading combined with:
- a gradient button
- a gradient background
- glowing cards
- animated particles
- multiple shadows
can quickly become excessive.
Gradient text usually works better as an accent than as the entire visual identity of a page.
4. How to create a multicolor gradient
You are not limited to two colors.
For example:
.gradient-text {
background: linear-gradient(
90deg,
#ff512f,
#dd2476,
#7c3aed,
#2563eb
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
You can also control exactly where colors appear:
.gradient-text {
background: linear-gradient(
90deg,
#ff512f 0%,
#dd2476 40%,
#7c3aed 70%,
#2563eb 100%
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
These percentages are called color stops. They give you much more control over how quickly one color transitions into another. CSS gradients support two or more color stops. (MDN Web Docs)
5. Gradient text on dark backgrounds
Dark interfaces are particularly well suited to gradient typography.
For example:
body {
background: #0f172a;
}
.gradient-text {
background: linear-gradient(
90deg,
#38bdf8,
#818cf8,
#c084fc
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
The result can work particularly well for:
- SaaS landing pages
- developer portfolios
- AI products
- technology websites
- startup websites
- gaming interfaces
- creative portfolios
But there is an important limitation: gradient text can create contrast problems.
A gradient may start with a highly visible color and gradually transition into a color that is difficult to distinguish from the page background.
MDN specifically recommends checking text contrast and providing a fallback color if the background effect fails to load or is unsupported. (MDN Web Docs)
6. Always think about the fallback
One of the biggest implementation mistakes is treating the gradient effect as more important than the text itself.
Your text needs to remain readable if the gradient is not displayed.
For example:
.gradient-text {
color: #2563eb;
background: linear-gradient(90deg, #2563eb, #9333ea);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Here, color provides a fallback.
If the browser does not render the gradient clipping as expected, the user should still have readable text.
You can also use a feature query for more deliberate progressive enhancement:
.gradient-text {
color: #2563eb;
}
@supports (background-clip: text) {
.gradient-text {
background: linear-gradient(90deg, #2563eb, #9333ea);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
}
This approach follows a broader principle I recommend for CSS effects: the effect should enhance the content, not become a dependency for understanding it.
7. Gradient text for only part of a heading
You do not have to make an entire heading gradient.
Sometimes highlighting one phrase is much more effective.
<h1>
Build
<span class="gradient-text">Better Websites</span>
</h1>
Then:
.gradient-text {
background: linear-gradient(90deg, #2563eb, #9333ea);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
This is particularly useful for landing-page headlines.
For example:
<h1>
Create
<span class="gradient-text">Faster Websites</span>
</h1>
Instead of making the entire sentence colorful, you establish a visual hierarchy.
That distinction matters.
If everything is emphasized, nothing is emphasized.
8. Animated gradient text
Once you understand static gradient text, animation is relatively straightforward.
You can make the gradient move across the letters:
.gradient-text {
background: linear-gradient(
90deg,
#ff0080,
#7928ca,
#2afadf,
#ff0080
);
background-size: 300% 100%;
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
animation: gradientMove 6s ease infinite;
}
@keyframes gradientMove {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
The important trick is:
background-size: 300% 100%;
combined with changing:
background-position
This gives the gradient enough space to move.
However, I would not automatically animate every gradient heading.
Animation should have a reason.
For a landing-page hero, a subtle movement may add visual interest. For a documentation website, dashboard, or content-heavy page, constantly moving text can become distracting.
9. A better approach for hover effects
Gradient text does not have to be permanently visible.
You can use it as a hover state.
.gradient-link {
color: #2563eb;
text-decoration: none;
}
.gradient-link:hover {
background: linear-gradient(
90deg,
#2563eb,
#9333ea
);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
You can make this more sophisticated by changing the gradient position.
A common technique is to create a background larger than the text and animate background-position. CSS-Tricks has demonstrated this approach for gradient link hover effects. (CSS-Tricks)
.gradient-link {
color: #111827;
background: linear-gradient(
to right,
#2563eb,
#9333ea,
#2563eb
);
background-size: 200% 100%;
background-position: 100%;
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
transition: background-position 300ms ease;
}
.gradient-link:hover {
background-position: 0%;
}
This produces a much more deliberate interaction than simply changing the text color.
10. Common mistakes that make gradient text look bad
The CSS itself is rarely the difficult part. Most problems come from implementation decisions.
Using too many colors
A gradient containing six unrelated colors may technically work but visually overwhelm the page.
Start with two colors.
Add a third only if it genuinely improves the transition.
Making body text gradient
I generally recommend keeping paragraphs, navigation, labels, and other information-heavy text in a solid color.
Gradient text is much more useful for:
- headings
- short phrases
- numbers
- promotional text
- decorative labels
- interactive elements
Long paragraphs with gradient coloring are usually harder to read.
Ignoring contrast
This is the most important problem.
A gradient can contain both highly readable and barely readable sections.
Always test the actual rendered text rather than assuming that two individually accessible colors automatically produce accessible gradient text.
Forgetting mobile
A heading that looks excellent on a large desktop screen can wrap onto three lines on a phone.
Because gradients are backgrounds attached to the element, wrapping can affect how the visual transition appears.
Test the actual heading at:
- desktop width
- tablet width
- narrow mobile width
Do not judge the effect only from your development monitor.
11. What about multiline gradient text?
This is one of the details people often discover only after implementing the effect.
Suppose you have:
<h1 class="gradient-text">
Build products people actually want
</h1>
On desktop it might occupy one line.
On mobile it could become:
Build products
people actually
want
The gradient is still being applied to the element, not independently designed for each line.
If you need very specific behavior across multiple lines, test the actual design at your target breakpoints. CSS-Tricks has also documented techniques involving background-clip and box-decoration-break for controlling how backgrounds behave across wrapped text. (CSS-Tricks)
For most website headings, though, I would avoid unnecessarily complicated solutions. Start with normal wrapping and see whether the result actually causes a visual problem.
12. Do you need JavaScript?
No.
For ordinary gradient text, JavaScript is unnecessary.
You can accomplish the effect using HTML and CSS:
<h1 class="gradient-text">Gradient Text</h1>
.gradient-text {
background: linear-gradient(90deg, #06b6d4, #8b5cf6);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
That means there is no reason to add a JavaScript library simply to produce this visual effect.
This is one of those situations where simpler implementation is generally better.
The browser can generate CSS gradients dynamically, so you also avoid loading an image just to reproduce a color transition. (MDN Web Docs)
13. A reusable gradient-text class
If you use gradient text repeatedly across a website, turn it into a reusable utility class.
.gradient-text {
background: linear-gradient(
90deg,
#2563eb,
#7c3aed,
#db2777
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
Then use it wherever necessary:
<h1 class="gradient-text">Modern Web Development</h1>
<h2 class="gradient-text">Build Something Better</h2>
<span class="gradient-text">New Feature</span>
You can also define the colors as CSS variables:
:root {
--gradient-start: #2563eb;
--gradient-middle: #7c3aed;
--gradient-end: #db2777;
}
.gradient-text {
background: linear-gradient(
90deg,
var(--gradient-start),
var(--gradient-middle),
var(--gradient-end)
);
background-clip: text;
-webkit-background-clip: text;
color: transparent;
-webkit-text-fill-color: transparent;
}
Now changing the visual identity of the entire website becomes much easier.
14. My recommended production version
If I wanted a clean, reusable implementation without unnecessary complexity, I would start here:
.gradient-text {
color: #2563eb;
background: linear-gradient(
90deg,
#2563eb 0%,
#7c3aed 50%,
#db2777 100%
);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
And:
<h1 class="gradient-text">
Build Better Websites
</h1>
From there, I would adjust only three things:
- Colors to match the brand.
- Gradient direction to match the composition.
- Font weight and size to make the effect readable.
I would not add animation, JavaScript, extra markup, filters, or complicated effects unless the design actually requires them.
15. The bigger lesson: use gradient text as design hierarchy
The easiest mistake is thinking that gradient text is a decoration you can add anywhere.
It is better understood as a visual hierarchy tool.
Compare:
Create Better Websites
with:
Create Better Websites
↑
gradient emphasis
The second version immediately tells the visitor that part of the message deserves attention.
That is why gradient text works particularly well in hero sections and short headlines.
It is not the gradient itself that makes the design effective. It is the contrast between the gradient element and everything around it.
Final gradient-text template
If you just need the code, this is the version worth keeping:
<h1 class="gradient-text">
Create Better Websites
</h1>
.gradient-text {
color: #2563eb;
background: linear-gradient(
90deg,
#2563eb,
#7c3aed,
#db2777
);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
Then customize the colors to your brand.
If you want animation:
.gradient-text {
color: #2563eb;
background: linear-gradient(
90deg,
#2563eb,
#7c3aed,
#db2777,
#2563eb
);
background-size: 300% 100%;
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradientMove 6s ease infinite;
}
@keyframes gradientMove {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
But start with the static version. If the design does not look good without animation, animation will not fix it.
Conclusion
Creating gradient text for a website does not require an image editor, JavaScript library, or complicated CSS.
The core technique is simple:
Create a CSS gradient → apply it as a background → clip the background to the text → make the normal text color transparent.
The real challenge is using the effect appropriately.
Keep the number of colors under control, maintain readable contrast, provide a fallback, test responsive layouts, and avoid turning every piece of text on the page into a rainbow.
For most websites, a subtle two- or three-color gradient on a strong heading is enough to create the visual emphasis you want without sacrificing usability.
And because the effect is generated with CSS rather than a raster image, it can scale with the text and avoids loading a separate graphic just to achieve the color transition. (MDN Web Docs)
Your next step: copy the basic example into a blank HTML file, change the two or three colors to match your website, and test the result on both desktop and mobile before adding animation or other effects.

Leave a comment