Fork me on GitHub

Behold, this is the mighty rainbow-text!

Installation

To get started, add following content to your <head> tag:

        <script src="https://haocen.github.io/rainbow-text/src/rainbow-text.js" type="module"></script>
      

And that's it! Now try to add <rainbow-text>Rainbow!<rainbow-text> somewhere visible on your website and enjoy the flowing colors.
You may also download the src/rainbow-text.js file and host the file anywhere you want.

Basic usage

You can nest rainbow-text in any element accepts text node, with any plain text content between a pair of <rainbow-text></rainbow-text> tags, for example:

Use with Font Awesome

In order to use font awesome, you need to load font awesome CSS into the shadow DOM.
This is required even if font awesome CSS is already loaded because of the shadow DOM styles isolation, following is an example:

        <rainbow-text>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
  Hello font awesome <i class="fa-brands fa-fort-awesome"></i>
</rainbow-text>
      
Will give you:
Hello font awesome

Customization

You can assign CSS value to following CSS variable names:
--animation-duration (default to "2s")
--animation-timing-function (default to "linear")
--animation-iteration-count (default to "infinite")
--animation-direction (default to "normal")
--animation-fill-mode (default to "none")
--animation-play-state (default to "running")
in order to fine tune the experience.
For example:

You can also set attribute flow-direction (default to "left-to-right") on the element:
For example:

Bugs and features

Feel free to open pull requests if you find a bug or want to implement a new feature.

Questons? Reach me at hello@haocen.me