CSS Text Color Change Animation

CSS Text Color Change Animation
Code Snippet:Text Animation
Author: Code Diary
Published: January 10, 2024
Last Updated: January 22, 2024
Downloads: 572
License: MIT
Edit Code online: View on CodePen
Read More

This CSS code snippet helps you to create a text color change animation on a webpage. It uses the CSS @keyframes rule to create the animation. The animation cycles through a series of keyframes, each of which specifies a different color for the text. The animation property is then applied to the text element in the HTML code.

You can use this animation in your web/app project to add a touch of visual interest to your web pages. It can also be used to create a more dynamic and engaging user experience.

How to Create Text Color Change Animation in CSS

1. First of all, add the Google Fonts CDN link to your HTML header to access the Lobster font used in the animation. (Optional)

<link href="https://fonts.googleapis.com/css2?family=Lobster&display=swap" rel="stylesheet">

2. Now, add the following HTML code within your document. Place it where you want the animated text to appear on your website. Adjust the class and content as needed.

<div class="text-animation">
<p>Color <span class="change"></span></p>
</div>

3. Apply styling to the text animation container and text elements using the following CSS code. Adjust the animation duration, colors, and content in the keyframes to suit your preferences.

.text-animation{
  background: linear-gradient(to right, #e0eafc, #cfdef3);
  padding: 150px;
}

.text-animation p{
	text-align: center;
	font-weight: bold;
	font-size: 2.9em;
	font-family: 'Lobster', cursive;
}
.change{
	color: #9c27b0;
}
.change:after{
	content: "";
	animation: change 15s linear infinite;
}
@keyframes change{
	 0%{
	 	content: "Red";
	 	color: red;
	 }
	  10%{
	 	content: "Yellow";
	 	color: yellow;
	 }
	 
	  20%{
	 	content: "Pink";
	 	color: pink;
	 }
	 
	  30%{
	 	content: "Black";
	 	color: black;
	 }
	 
	  40%{
	 	content: "Violet";
	 	color: #ee82ee;
	 }
	 
	  50%{
	 	content: "Orange";
	 	color: orange;
	 }
	 
	  60%{
	 	content: "Green";
	 	color: green;
	 }
	 
	  70%{
	 	content: "Dark Magenta";
	 	color: #8b008b;
	 }
	 
	  80%{
	 	content: "Purple";
	 	color: #800080;
	 }
	 
	  90%{
	 	content: "Indigo";
	 	color: #4b0082;
	 }
	 
	  100%{
	 	content: "Lime Green";
	 	color: #32cd32;
	 }
	 
}

That’s all! hopefully, you have successfully created a text color change animation on your website. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X