In this article, we’ll create a mesmerizing Rainbow Text Animation using only HTML and CSS. This vibrant gradient effect adds a playful, attention-grabbing visual to your headlines or hero sections — and yes, it’s all done without a single line of JavaScript.
What You’ll Learn
In this tutorial, you’ll discover how to:
- Style text with an animated rainbow gradient.
- Use
-webkit-background-clip
andtext-fill-color
for rich visual effects. - Apply seamless animation using CSS
@keyframes
. - Enhance typography with text shadows and uppercase spacing.
This is a simple yet striking way to add motion and color to your web typography.
HTML & CSS: Rainbow Text in Action
The effect centers around a single <span>
element inside a styled paragraph. Here’s the full code to get started:
<p>
Color the Web with
<span>Rainbow Text</span>
— Pure CSS Magic —
</p>
body {
margin: 0;
background: #0f0f0f;
font-family: "Segoe UI", sans-serif;
color: rgba(255, 255, 255, 0.2);
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
}
p {
text-transform: uppercase;
letter-spacing: 0.3em;
padding: 2.5em;
border-top: 3px solid rgba(255, 255, 255, 0.2);
border-bottom: 3px solid rgba(255, 255, 255, 0.2);
display: inline-block;
}
p span {
font-size: 4em;
font-weight: 900;
letter-spacing: 0;
display: block;
/* Rainbow Gradient */
background: linear-gradient(
270deg,
#ff0000,
#ff9900,
#ffff00,
#33cc33,
#0066ff,
#6600cc,
#ff3399,
#ff0000
);
background-size: 200% 200%;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
animation: rainbowMove 5s linear infinite;
text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}
@keyframes rainbowMove {
0% {
background-position: 0% 50%;
}
100% {
background-position: 100% 50%;
}
}
This glowing rainbow effect is flexible and lightweight — a perfect upgrade for standout text anywhere on your site. Use it in titles, banners, or even as a stylish button label!
See the Pen Animated Rainbow Gradient Text Effect by Codeymaze (@Codeymaze) on CodePen.