Rainbow text animation using only CSS

Azazel picture Azazel · Feb 15, 2019 · Viewed 15.3k times · Source

I got inspired by this Rainbow Text Animation rainbow-text-animation, and I would like to use only CSS to make this happen instead of all that complicated SCSS coding.

I got what I like so far and now I just want to make it go from left to right AND having multiple colors in one entire line instead of one color at a time.

Run the code snippet to see what I'm talking about.

So as you can see, I want as many colors I want in one line and not one color in the entire line (one at a time).

Answer

Austen Holland picture Austen Holland · Feb 15, 2019

You can achieve this effect by using a moving gradient background, color to transparent, and background clip to text.

#shadowBox {
    background-color: rgb(0, 0, 0);
    /* Fallback color */
    background-color: rgba(0, 0, 0, 0.2);
    /* Black w/opacity/see-through */
    border: 3px solid;
}

.rainbow {
    text-align: center;
    text-decoration: underline;
    font-size: 32px;
    font-family: monospace;
    letter-spacing: 5px;
}
.rainbow_text_animated {
    background: linear-gradient(to right, #6666ff, #0099ff , #00ff00, #ff3399, #6666ff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: rainbow_animation 6s ease-in-out infinite;
    background-size: 400% 100%;
}

@keyframes rainbow_animation {
    0%,100% {
        background-position: 0 0;
    }

    50% {
        background-position: 100% 0;
    }
}
<div id="shadowBox">
    <h3 class="rainbow rainbow_text_animated">COMING SOON</h3>
</div>