This content originally appeared on 1stWebDesigner and was authored by 1WD Crew
Web design takes a captivating turn when CSS comes into play. It enables a world of transformations, such as taking static text elements and infusing them with life. Our focus today is one such engaging transformation – animate gradient text using CSS.
So, let’s demonstrate how a seemingly complex effect can be achieved with a few lines of code.
Setting Up the Text in the HTML
We begin by defining our text element in HTML, which in this case is a simple heading:
<h1 class="animated-gradient">1stWebDesigner</h1>
Here, we create an <h1>
element with a class called “animated-gradient”. This class becomes our anchor for creating the gradient animation in CSS.
Unfolding the Gradient Animation
The core part lies within our CSS. Let’s define the gradient and set it in motion with the following code:
/* Google Fonts for Open Sans */ @import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@700&display=swap'); /* Define animation */ @keyframes gradient-shift { 0% {background-position: 0%} 100% {background-position: 100%} } /* Styling our animated gradient text */ .animated-gradient { font-family: 'Open Sans', sans-serif; font-size: 2em; background: linear-gradient(270deg, #ff4b59, #ff9057, #ffc764, #50e3c2, #4a90e2, #b8e986, #ff4b59); background-size: 200%; -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: gradient-shift 3s ease-in-out infinite; }
Our CSS setup does the following:
@import url
: This directive fetches theOpen Sans
font from Google Fonts, noted for its modern and clean aesthetics.@keyframes
: Here, we define an animation namedgradient-shift
. This animation creates the illusion of motion in the gradient by shifting the background’s position from 0% to 100%.font-family
andfont-size
: These properties set our text’s font toOpen Sans
and its size to2em
.background
: This property generates a linear gradient using a striking array of colors. The gradient direction is set to 270 degrees, providing a left-to-right color flow.background-size
: This property, set to200%
, enlarges the background, contributing to the illusion of movement.-webkit-background-clip
and-webkit-text-fill-color
: These properties render the text transparent, allowing the animated gradient to shine through.animation
: Lastly, we deploy ourgradient-shift
animation. It uses anease-in-out
timing function for smooth transitions and loops indefinitely, creating an ever-changing cascade of colors.
The Result
And there we have it! Check out the vibrant, animated gradient text:
See the Pen
Animated Gradient Text by 1stWebDesigner (@firstwebdesigner)
on CodePen.0
Final Thoughts
The process of creating the animated gradient text effect is surprisingly straightforward, but the creative opportunities it unveils are far-reaching. With this foundational knowledge, you can experiment with different color schemes and gradient directions, apply the animation to various elements like buttons or headers, and even incorporate subtle animated accents into your design.
Remember, the real beauty of CSS is in its flexibility and power – it provides a vast canvas for creativity. You could also explore further with CSS keyframes to manipulate other properties and add more dynamic animations to your design. Feel free to dive deeper into the world of CSS animations with our guide on CSS keyframes.
This content originally appeared on 1stWebDesigner and was authored by 1WD Crew
1WD Crew | Sciencx (2023-06-28T19:01:08+00:00) How to Animate Gradient Text Using CSS. Retrieved from https://www.scien.cx/2023/06/28/how-to-animate-gradient-text-using-css/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.