CSS Gradient text effect

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
Search for a command to run...

I'm a full-stack developer from South Africa 🇿🇦. I love writing about JavaScript, HTML and CSS.
No comments yet. Be the first to comment.
Most of you know me for my consistency, a golden arrow in my blog series. I've written 1000 articles in 1008 days! Almost an article a day, and my honeymoon was the only holiday I ever took. I'm super proud of this achievement; it has been a fantasti...

It's not the first time I'll be talking about community. I think it's an essential aspect of any successful tool. This shows in my previous explorations of Astro, Medusa, and now Vendure as well. All these products thrive in a super open, welcoming, ...

The cool part about Vendure is how easy it is to set up and how abstract each layer is. Basically, we get the following elements: External database Server Worker Admin UI Frontend While this is amazing, it also brings a bit of complexity when it co...

The previous article looked at customizing Vendure on a data and process level. In this article, we'll look at customizing emails, as they are often a big part of a webshop system. We'll be looking at two different layers of customization for customi...

Even though Vendure is a pretty significant project out of the box, in some cases, we might want to go in and modify some elements to work to our specific use case. In this article, I'll take a high-level look at some elements we can customize within...

Today we are creating a super cool and pretty quick CSS effect.
I really love this effect. It's not super happy and can be made by just CSS.
Because it's CSS based, we have the option even to animate it if we want to. (I'll leave that up to you)
The end result of today's article:

I'll be guiding you to create this cool effect yourself, in just a couple of lines of CSS!
As for the HTML, we only need the following:
<h1>Super Cool<br />Gradient Effect</h1>
As you can see, I've added a break (<br />) just because I like to showcase it even works on two lines.
Now let's move to our CSS setup.
We'll start by styling our body, so we center our element inside the <h1>.
body {
display: grid;
place-items: center;
min-height: 100vh;
background: #000;
}
I use CSS Grid to center everything perfectly.
Then in my example, I'm using a black background to make it pop more.
Now we need to get cracking on our heading style.
h1 {
font-family: Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 6vmax;
}
We start by defining a font we like and making it nice and big.
I'm using a 6vmax, which is a scalable viewport unit.
This results in the following:

The next step is to add our gradient. We are using the background-image to set our gradient.
h1 {
font-family: Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 6vmax;
background-color: #5390d9;
background-image: linear-gradient(45deg, #6930c3, #5390d9);
}
As you can see, I also set a fallback color in case the gradient isn't supported.
I'm using a basic CSS linear gradient with only two colors.
You can extend these to support even more colors or fancy gradients.
You can use this cool generator for CSS gradients
Our result so far is pretty weird:

As you can see above, the text is now black and has a gradient surrounding it. It's close, but we're not there yet.
Let's add the text gradient effect.
We make use of the background-clip property and set the text-fill-color to transparent.
The background-clip makes sure the gradient goes on top of the text, and the text-fill will make it pop through.
h1 {
font-family: Roboto, 'Helvetica Neue', Arial, sans-serif;
font-size: 6vmax;
background-color: #5390d9;
background-image: linear-gradient(45deg, #6930c3, #5390d9);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
-moz-background-clip: text;
-moz-text-fill-color: transparent;
}
Now we get this amazing result, have a look around on this Codepen.
See the Pen eYdgOVg by Chris Bongers (@rebelchris) on CodePen.
This whole setup doesn't have full support, but the elements these days are quite widely supported.
I've shown the background-clip since it's an important part.

Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter