Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rainbow text animation using only CSS

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).

#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;
  animation: colorRotate 6s linear 0s infinite;
}

@keyframes colorRotate {
  from {
    color: #6666ff;
  }
  10% {
    color: #0099ff;
  }
  50% {
    color: #00ff00;
  }
  75% {
    color: #ff3399;
  }
  100% {
    color: #6666ff;
  }
}
<div id="shadowBox">

  <h3 class="rainbow">COMING SOON</h3>

</div>
like image 260
Azazel Avatar asked Feb 15 '19 03:02

Azazel


People also ask

How do you make the text color a rainbow in CSS?

One method for adding a rainbow is to do stacked text shadows. In this example, I have 9 different text shadows all offset by 4px. For example, the first shadow is -4px 4px #ef3550, . The first negative value places the shadow to the left of the letter.

How do you write multicolor text in CSS?

Steps to add multicolor into text: Add a simple text inside the <div> tag with the required selector. Apply the linear gradient property with any colors of your choice. Apply webkit properties that will fill the text with the gradient background and declare the color property with transparent background.

How do you make text rainbow in HTML?

Another way is creating a text with separate elements by using the HTML <span> tag, which is an empty container. This means that you create a multicolor text by putting each letter in a separate element to define a different color for each letter of your text.

How to use pure CSS rainbow text animation?

When you move the mouse over the text, you will see Pure CSS Rainbow Text Animation. Below I have given a demo that will help you to understand how this text animation works. As you can see above, I used black as the background color for a web page.

How many colors can be seen in this simple rainbow text animation?

The text size has been kept slightly larger and the color white has been used. When you click on this text or move the mouse, you can see the Rainbow Text shadow in the background. A total of 6 colors can be seen in this Simple Rainbow Text Animation.

How do I change the speed of the rainbow text animation?

You can freely change the speed by adjusting the duration of the .rainbow_text_animated animation. (Say changing 6s to 12s to double the slowness) At the moment it is moving the gradient background to the right, then to the left, then back to the right etc. This creates the "loop" effect. Oh sweet man! Thanks for the clarification!

Can I change the color of the rainbow text?

Here we have used the background black color to clearly understand the colors of the Rainbow Text. You can change this color when you use it in your project. It's easy to make if you have a basic idea about HTML and CSS. Below I have shared all the source code and step-by-step tutorials.


2 Answers

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>
like image 73
Austen Holland Avatar answered Oct 06 '22 12:10

Austen Holland


#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;
  animation: colorRotate .5s linear 0s infinite;
}

@keyframes colorRotate {
  from {
    color: #6666ff;
  }
  10% {
    color: #0099ff;
  }
  50% {
    color: #00ff00;
  }
  75% {
    color: #ff3399;
  }
  100% {
    color: #6666ff;
  }
}
<div id="shadowBox">

  <h3 class="rainbow">VERB</h3>

</div>
like image 31
Scott Wright Avatar answered Oct 06 '22 13:10

Scott Wright