🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
Introduction
A blinking text effect can grab attention and create a dynamic visual impact. This can be achieved using CSS @keyframes combined with the visibility or opacity property to toggle the text's visibility at intervals.
In this tutorial, you'll learn how to create a blinking text effect using HTML and CSS.
Problem Statement
Create a CSS code that:
- Animates text to blink on and off using
@keyframesandvisibilityoropacity. - Demonstrates how to control the blink speed and repetition.
Example:
- Input: A paragraph element with the text "Blinking Text".
- Output: The text blinks continuously.
Solution Steps
- Use
@keyframesfor Blinking Animation: Define keyframes to animate the visibility or opacity of the text. - Apply the Blinking Effect to Text: Use the
animationproperty to control the blinking speed and repetition.
HTML Structure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blinking Text Effect</title>
<style>
/* Step 1: Define keyframes for blinking text */
@keyframes blink {
0% {
opacity: 1; /* Fully visible */
}
50% {
opacity: 0; /* Invisible */
}
100% {
opacity: 1; /* Fully visible */
}
}
/* Step 2: Apply blinking effect to text */
.blinking-text {
font-size: 2rem;
color: #e74c3c;
font-family: Arial, sans-serif;
animation: blink 1s infinite; /* 1-second blink, infinite loop */
text-align: center;
margin-top: 100px;
}
/* Center the text container */
.container {
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<p class="blinking-text">Blinking Text Effect</p>
</div>
</body>
</html>
Output
Explanation
Step 1: Define @keyframes for Blinking Text
The
@keyframesrule defines the blinking effect by alternating theopacitybetween1(fully visible) and0(invisible):@keyframes blink { 0% { opacity: 1; } 50% { opacity: 0; } 100% { opacity: 1; } }At
0%and100%, the text is fully visible, and at50%, it becomes invisible, creating the blinking effect.
Step 2: Apply the Blinking Effect to Text
To apply the blinking animation, use the
animationproperty:.blinking-text { animation: blink 1s infinite; }The
1sspecifies that the text will blink every second, andinfiniteensures the animation loops continuously.
Step 3: Center the Text
- Use
text-align: centerto center the text within the container:.container { text-align: center; margin-top: 100px; }
Conclusion
Creating a blinking text effect in CSS is simple using @keyframes and the opacity property. This effect can be useful for drawing attention to important information and making your text blink at a set interval to create a dynamic visual impact on your web page.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment