Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
Fading Text Animation Effect Using CSS3
Next article icon

Text switching animation using CSS

Last Updated : 05 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Text Switching animation is an essential part of modern web engagement concepts. There are many types of Text Switching animation, depending on your imagination as well. Here in this tutorial, we will be learning to transition the words with a blur effect. The words come from the front blurring out the words which are behind until after a second they disappear. Here we are doing this for text, the next level of the same would be to transition the images of a carousel like the text.

Check out this example below:

Approach:

  • For the carousel, the loop must be of an infinite time period.
  • Make an outer div with the class name of the container to center the child elements and also to place the child items relative to it.
  • Add a margin to the top and left side to center the child items, in this case, text.
  • Wrap the text inside a div with the class name of the word and animate it for the infinite time period.
  • Add a delay to each child element to animate it with some time in between otherwise all the items will be displayed at the same time.
  • At last, use the keyframes to add the blur effect at an appropriate opacity level. 
  • Yes, this is that simple!

The syntax for Keyframes:

@keyframes animation_name {
keyframes-selector {
css-styles;
}
}

HTML Code: Making an outer container and adding each word inside a separate div to animate them separately.

Note: If you have multiple inside a single element to display at once, keep the animation duration of the next element a little late and blur the long element a little early in keyframes.

HTML
<div class="container">     <div class="word">GeeksForGeeks</div>     <div class="word">Is</div>     <div class="word">Amazing...</div> </div> 

CSS Code: We have styled the body element for demo purposes you will have to style it according to your needs. 

  • The container is the parent element so we will position the child items relative to it and not the whole body.
  •  Filter contrast is necessary to spread the blur effect like an ellipse shape with some striations within to make it appealing.
  •  You can have your own font family which you like, we have opted for monospace here.
  • Word div are child elements and we add the main hero, and the animation to it keeping the margin auto so that it doesn't shy away in the corner. 
  • Adding the translation everything is stacked upon each other. Delaying the animation of each element so that things go according to plan. 
  • Keyframes times the blur and opacity effect in the transition animation.
CSS
body {     background: #151515;     height: 100vh;     display: grid;     place-items: center; }  .container {     position: relative;     font-family: monospace;     color: rgb(255, 255, 255);     font-size: 4em;     filter: contrast(15); }  .word {     position: absolute;     top: 50%;     left: 50%;     transform: translate(-50%, -50%);     animation: switch 8s infinite ease-in-out;     min-width: 100%;     margin: auto; }  .word:nth-child(1) {     animation-delay: -7s; }  .word:nth-child(2) {     animation-delay: -6s; }  .word:nth-child(3) {     animation-delay: -5s; }  @keyframes switch {      0%,     5%,     100% {         filter: blur(0px);         opacity: 1;     }      50%,     80% {         filter: blur(180px);         opacity: 0;     } } 

Complete Code Combined:  Here we combine all the code and you can copy this to try it yourself don't forget to add your own art to it.

HTML
<!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8" />     <meta http-equiv="X-UA-Compatible" content="IE=edge" />     <meta name="viewport"            content="width=device-width,initial-scale=1.0" />     <title>Text switching animation using CSS</title>      <style>         body {             background: #151515;             height: 100vh;             display: grid;             place-items: center;         }          .container {             position: relative;             font-family: monospace;             color: rgb(255, 255, 255);             font-size: 4em;             filter: contrast(15);         }          .word {             position: absolute;             top: 50%;             left: 50%;             transform: translate(-50%, -50%);             animation: switch 8s infinite ease-in-out;             min-width: 100%;             margin: auto;         }          .word:nth-child(1) {             animation-delay: -7s;         }          .word:nth-child(2) {             animation-delay: -6s;         }          .word:nth-child(3) {             animation-delay: -5s;         }          @keyframes switch {              0%,             5%,             100% {                 filter: blur(0px);                 opacity: 1;             }              50%,             80% {                 filter: blur(180px);                 opacity: 0;             }         }     </style> </head>  <body>     <div class="container">         <div class="word">GeeksForGeeks</div>         <div class="word">Is</div>         <div class="word">Amazing...</div>     </div> </body> </html> 

Output: So here it is our amazing text-switching animation, hope you will make it better by adding your creativity to it. Happy Styling! 


Next Article
Fading Text Animation Effect Using CSS3

S

satyamm09
Improve
Article Tags :
  • CSS
  • Web technologies
  • CSS-Properties
  • CSS-Selectors
  • CSS-Questions

Similar Reads

  • Loading Text Animation Effect using CSS
    There are a lot of animations possible in CSS and today we will look at the loading text animation. The basic idea behind the working of this animation is the application of animation delay. Every alphabet is delayed by .1s so that each alphabet animates with a little delay and give the loading anim
    3 min read
  • Fading Text Animation Effect Using CSS3
    The fading text animation effect is one of the most demanding effects on UI/UX designing. This effect can be achieved by using HTML5 and CSS3. In the fading text effect, whenever we load the window, the text will slowly start disappearing. We can implement this effect using the animation property in
    2 min read
  • Text Animation using SVG Image
    What is SVG? SVG stands for Scalable Vector Graphics. It is an image format based on XML. It creates different geometric shapes that can be combined to make two-dimensional graphics. We are going to use an SVG image to create a text animation effect. The SVG images can be downloaded from the interne
    15+ min read
  • Foundation CSS Orbit Using Animation
    Foundation CSS is an open-source front-end framework that makes it simple and quick to create an appealing responsive website, email, or app. ZURB released it in September 2011. Numerous businesses, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. This platform, which resembles SaaS, is
    4 min read
  • How to create text-fill animation using CSS ?
    A text-fill animation using CSS is a visual effect where the content of text gradually fills with a color, gradient, or pattern over time. This animation can create dynamic, eye-catching effects for headings or titles by adjusting properties like background-size, clip-path, or keyframe animations. A
    2 min read
  • Animation using clip-path property in CSS
    The clip-path CSS property is used to clip the region in such a way that element in the clipped regions are shown. In this article, we will see how we can use the clip-path and @keyframes together to create an image animation. Step 1: Create a div with a class container that should include <img
    2 min read
  • How to pause/play animation using CSS ?
    CSS helps to animate HTML elements without using JavaScript. You can play and pause the animation applied to HTML elements using animation-play-state property of CSS. The animation-play-state property has 2 values:paused - Pauses an ongoing animation.running - Starts a paused animation (default valu
    2 min read
  • Text Animation using HTML & CSS @keyframes Rule
    Text animation is a powerful tool for creating visually engaging and interactive web pages. HTML and CSS offer a range of options for creating advanced text animation effects. In Particular, the CSS '@keyframes' rule comes in handy. The CSS '@keyframes' rule is used to define animations that change
    3 min read
  • How to Create Jumping Text 3D Animation Effect using CSS ?
    In this article, you will learn to implement Jumping Texts animation effect using simple HTML and CSS. HTML is used to create the structure of the page and CSS is used to set the styling. HTML Code: In this section, we will design the basic structure of the body. [GFGTABS] html <!DOCTYPE html>
    4 min read
  • CSS animation-timing-function Property
    The animation-timing-function property in CSS is used to specify how an animation makes transitions through keyframes. It defines the speed curve of the animation, determining how the intermediate keyframes are calculated and the pacing of the animation. Syntax: animation-timing-function: linear | e
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences