Saturday, June 28, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

How to Animate Text Gradients and Patterns in CSS — SitePoint

April 11, 2024
in Cloud & Programming
Reading Time: 3 mins read
0 0
A A
0
Share on FacebookShare on Twitter



In this quick tip, we’ll show how easy it is to animate a background gradient with CSS. In a recent article, we showed how to set a background gradient on text. The CodePen demo below shows the result. Make sure to read through that article if you’re not sure how we got to this result, as we’ll build on this example below. For the sake of this demo, let’s add in some extra colors to our gradient background:

background-image: linear-gradient( 45deg, #ffb3ba, #c49c6e, #bfbf76, #77b084, #ff7e74, #3b82f6, #c084fc, #db2777 );

If we turn off background-clip: text and text-color: transparent for a moment, we get a better sense of how our gradient fills the text’s content box. Let’s now go through the steps of animating our background gradient.

Step 1: Adjusting the Background Size
To animate our gradient background, we need to make it bigger than the text’s content box so we can’t see all of it at once. We can do that with the handy background-size property. (You can read all about background-size here.) I’m going to set the width of our background gradient to three times the width of our heading element:

background-size: 300% 100%;

Now, only a third of the gradient background will be visible at any one time, as seen below.

Step 2: Setting an Animation
Next, we’ll set up an animation that will move the background around so that we’ll see different parts of it over time. We can set up a simple animation rule like so:

animation: gradientAnimation 8s linear infinite;

That will move the background back and forth once every 16 seconds. Next, we’ll set up an @keyframes statement:

@keyframes gradientAnimation {
0% { background-position: 0; }
to { background-position: 100%; }
}

This simple @keyframes statement will move our background from the top left to the bottom right every eight seconds. In the Pen below, we’ve once again disabled background-clip: text and color: transparent so we can see what’s happening in the background. Once we re-enable background-clip: text and color: transparent, we see the finished product. Pretty cool!

Animating a Background Image
In our article on adding gradient effects and patterns to text, we also used a floral background image. (See the Pen for that here.) Let’s have a go at animating that background too. We’ll do it slightly differently, as we don’t want to distort the background image. Let’s remove background-size: contain from the original demo and not set a background size at all. That leaves us with this:

color: transparent;
-webkit-background-clip: text;
background-clip: text;
background-image: url(floral.jpg);
-webkit-text-stroke: 1px #7512d7;
text-stroke: 1px #7512d7;
animation: gradientAnimation 20s linear infinite;
animation-direction: alternate;

@keyframes gradientAnimation {
0% { background-position: 0; }
to { background-position: 100%; }
}

The result is shown in the CodePen demo below. Try turning off background-clip: text and text-color: transparent for a moment if you want to see what’s happening in the background. Our background image is repeating by default, which doesn’t look too bad for this particular image. (Just out of interest, try adding background-repeat: no-repeat to see what what happens without a repeating background.) In other situations, where the background image doesn’t tile so well, you might want to prevent the image repeating and then use background-size to make the image larger, like we did with the gradient background above. For example:

background-repeat: no-repeat;
background-size: 120%;

Here’s the effect of doing that on our floral demo.

Conclusion
We could do much more spectacular animations that this, but the aim was to keep it simple here. You can dig deeper into CSS keyframes and animations in How to Get Started with CSS Animation. You can also play around with the timing of the animation, angle of the gradient and so on. As mentioned in the previous article, have fun with this but don’t go overboard, as too much of this kind of animation can become annoying. A subtle animated background on a heading might just add that touch of interest or intrigue you need to keep your audience engaged.



Source link

Tags: AnimatecssGradientsPatternsSitePointText
Previous Post

Announcement – The Solana Development Course Launched

Next Post

15 Short Artificial Intelligence (AI) Courses on DeepLearning.AI

Related Posts

Top 20 Javascript Libraries You Should Know in 2024
Cloud & Programming

Top 20 Javascript Libraries You Should Know in 2024

June 10, 2024
Simplify risk and compliance assessments with the new common control library in AWS Audit Manager
Cloud & Programming

Simplify risk and compliance assessments with the new common control library in AWS Audit Manager

June 6, 2024
Simplify Regular Expressions with RegExpBuilderJS
Cloud & Programming

Simplify Regular Expressions with RegExpBuilderJS

June 6, 2024
How to learn data visualization to accelerate your career
Cloud & Programming

How to learn data visualization to accelerate your career

June 6, 2024
BitTitan Announces Seasoned Tech Leader Aaron Wadsworth as General Manager
Cloud & Programming

BitTitan Announces Seasoned Tech Leader Aaron Wadsworth as General Manager

June 6, 2024
Copilot Studio turns to AI-powered workflows
Cloud & Programming

Copilot Studio turns to AI-powered workflows

June 6, 2024
Next Post
15 Short Artificial Intelligence (AI) Courses on DeepLearning.AI

15 Short Artificial Intelligence (AI) Courses on DeepLearning.AI

Is robotics about to have its own ChatGPT moment?

Is robotics about to have its own ChatGPT moment?

Creating Viral Reach on YouTube Even if You’re Brand New

Creating Viral Reach on YouTube Even if You’re Brand New

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
How ‘Chain of Thought’ Makes Transformers Smarter

How ‘Chain of Thought’ Makes Transformers Smarter

May 13, 2024
Amazon’s Bedrock and Titan Generative AI Services Enter General Availability

Amazon’s Bedrock and Titan Generative AI Services Enter General Availability

October 2, 2023
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
The Importance of Choosing a Reliable Affiliate Network and Why Olavivo is Your Ideal Partner

The Importance of Choosing a Reliable Affiliate Network and Why Olavivo is Your Ideal Partner

October 30, 2023
Managing PDFs in Node.js with pdf-lib

Managing PDFs in Node.js with pdf-lib

November 16, 2023
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In