Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryWeb Content Preparation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Gradient-colored Text

Text can be colored with horizontal or vertical color gradients. My own book Sadine; The Magic Elf is used to demonstrate how it can be done.

Sadine; The Magic Elf book cover

Note that the font used on the book cover is unlikely to be immediately available on every reader's computer. Thus, the CSS for the font in the article examples is font-family:"Brush Script MT"; and font-weight:bold;. Brush Script MT should be a web-safe font.

The idea for this article is how to do the color gradient, not necessarily to match the font.

Therefore, let's do it. Here is the example we'll work with.

Sadine

Here is the source code for the above. Following that, we'll go through each of the CSS declarations the source code presents.

<style type="text/css">
.text-color-gradient {
    background:linear-gradient(to right, hsl(140, 100%, 55%), hsl(240,100%,30%), hsl(140, 100%, 55%));
    background-clip:text;
    color:transparent;
    font-family:"Brush Script MT";
    font-weight:bold;
}
</style>
<div class="text-color-gradient" style="display:table; font-size:1in;">
Sadine
</div>

Let's address the CSS in the above source code:

background:linear-gradient(...) puts a color-gradient into the div as a background. If you didn't have any other of the example CSS in place, you would get only a box with a color gradient. Like this:

 
 
 

The CSS Color Gradients article has more information about linear gradients.

The next two CSS declarations work together to remove all of the background except what is behind the text: background-clip:text and color:transparent

background-clip:text removes the background that would show outside the text. color:transparent makes the text transparent so the background remaining behind the text can show through.

Note, if you expect older versions of browsers to view the web page with color-gradient text, then add -webkit-background-clip:text to the style so those folks can see the effect, too.

The font-family and font-weight CSS properties specify the font and weight.

You now have the tools you need to make color-gradient text.

To visualize how the browser constructs the color-gradient text, first visualize a div with a color-gradient background. Then visualize the background showing through the text within the div. Last, visualize all the background around the text gone poof.

That's pretty much how it works.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2025 Will Bontrager Software LLC