Text with Gradient Background

Text with Gradient Background

Here’s something that looks fun.

Gradient Text!

Even Animation!

Here’s the fiddle:

Of course, you’d want it in your own colors, right?

So just head on over to
Ultimate CSS Gradient Editor
for the gradient css codes and

Gradient Animator
for the animation.

 

Now that you’re all ready with your links and css codes and stuff, we can dive in.

Basically, what we’re going to do is take those gradients and use them as backgrounds to punched-out text.

 

So we take two elements: the background, and the punched out text.

Here’s an example of a gradient:

h1.grad-back {
background: rgb(181,189,200); 
background: -moz-linear-gradient(left, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); 
background: -webkit-linear-gradient(left, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%);
background: linear-gradient(to right, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); 
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=1 ); }

and here’s some punched out text:

.clipped {
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;}

Add them together, and we get:

h1.grad-back {
background: rgb(181,189,200); 
background: -moz-linear-gradient(left, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); 
background: -webkit-linear-gradient(left, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%);
background: linear-gradient(to right, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); 
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=1 ); 
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

So that’s the first one. The one with just the gradient background.

Here’s what the animation looks like:

h1.moving {
background: linear-gradient(270deg, #5b20ad, #2da9ef, #06b050, #e6da25);
background-size: 800% 800%;
-webkit-animation: blockbusteranimation 8s ease infinite;
-moz-animation: blockbusteranimation 8s ease infinite;
-o-animation: blockbusteranimation 8s ease infinite;
animation: blockbusteranimation 8s ease infinite;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
@-webkit-keyframes blockbusteranimation {
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
}
@-moz-keyframes blockbusteranimation {
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
}
@-o-keyframes blockbusteranimation {
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
}
@keyframes blockbusteranimation { 
    0%{background-position:0% 50%}
    50%{background-position:100% 50%}
    100%{background-position:0% 50%}
}

 
[sc name=”customcss”]

So it’s pretty cool!

However… One problem:
As is with everything good on the internet, this does not work on IE.
Notice the “-webkit” part? Yeah, it doesn’t work on IE. So, you should probably add an IE specific stylesheet that just gives the text a single color.

So there you have it! A pretty awesome way to get gradients behind your text without using images. (for the modern browser people)

PS. The Divi theme version will be up real soon, and the link is here.
 
[sc name=”learn css”]
 
[sc name=”responsive-ad”]
 
[sc name=”podcast”]
 
 

 

Photo by Sam Headland on Unsplash

Leave a Reply

Your email address will not be published. Required fields are marked *

    New tutorials

    Use a featured video in post templates with Breakdance
    ACF repeater fields as accordions in Breakdance
    Breakdance 2 vs. Divi 4
    Breakdance 2 for Agencies

    Why no ads?

    Hi, I'm PK, and I maintain and publish content on this site for two reasons.

    1. To give back to the community. I learned so much from people's tutorials and StackOverflow that I wanted to contribute and help others.

    2. To provide a more structured learning experience. People struggle to find the course that guides them from start to finish, based off of real life experience, and my courses provide that.

    The only "ads" I have here are for my own courses, and maybe an affiliate link, but that's it. They fund the website resources and provide more motivation for me to produce better content.

    Any bit of interest helps. Even sharing with your friends, suggesting my courses to your developer or designer, or subscribing to my YT channel, or joining our Discord. Thanks and I'll see you around!

    There's a newsletter!

    Sign up to the newsletter for the occasional updates on courses, products, tutorials, and sales.