DEV Community

Cover image for CSS Rainbow Text Animation 🌈
langford
langford

Posted on • Edited on

4 2

CSS Rainbow Text Animation 🌈

In this tutorial, we'll make a simple CSS rainbow text animation.

css rainbow text animation gif

Click here to checkout the source code for this tutorial.

HTML

In the index.html file, we'll only need an h1 tag with text.

<h1>Superdev.</h1>

Enter fullscreen mode Exit fullscreen mode

CSS

Our CSS file will include the h1's basic styling as well as the code for animating the text.

Styling the text

h1 {
    background-clip: text;
    background: url('https://vivaldi.com/wp-content/uploads/colors-1024x656.png');
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: text 3s linear infinite;
}
Enter fullscreen mode Exit fullscreen mode

Because no animations have been applied up to this point, our text will look like this:
css rainbow text without animation

Adding animations

@keyframes text {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 100%;
    }

    100% {
        background-position: 0% 50%;
    }
}
Enter fullscreen mode Exit fullscreen mode

That's it 🎉

You should see something like this when you open the index.html file in your browser.

css rainbow text animation gif

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay