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:
How to Create Jumping Text 3D Animation Effect using CSS ?
Next article icon

How to Use Icons to Make an Animated Effect Using CSS?

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

Icons are small, visual representations of actions or content. They can add a lot of style and functionality to a website, especially when combined with animations. we'll explore how to use CSS to animate icons, giving your website a lively and interactive touch.

These are the following approaches for using icons to make an Animated Effect using CSS:

Table of Content

  • Using Pulse Animation
  • Using Bounce Animation
  • Using Rotate Animation

Using Pulse Animation

This approach makes an icon appear to "pulse" by smoothly enlarging and then shrinking it. It uses the @keyframes rule to define how the icons scale up and down over time. The icon grows bigger and then returns to its original size in a repeating cycle, creating a pulse effect.

Example: Let's create step wise a simple animated heart icon. We’ll use the Font Awesome library for the heart icon and CSS to animate it.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport"            content="width=device-width, initial-scale=1.0">     <title>Document</title>     <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">  </head>  <body>     <style>         .icon-container {             text-align: center;             margin-top: 50px;         }          .fa-heart {             font-size: 48px;             color: red;             animation: pulse 1.5s infinite;         }          @keyframes pulse {             0% {                 transform: scale(1);             }              50% {                 transform: scale(1.2);             }              100% {                 transform: scale(1);             }         }     </style>      <div class="icon-container">         <i class="fas fa-heart"></i>     </div> </body>  </html> 

Output:

Recording-2024-08-05-114722

Using Bounce Animation

This approach creates a "bouncing" effect by making the icon move up and down. It uses keyframes to define how far the icon moves at different points in the animation. The icon jumps up and then comes back down, with smaller bounces as it returns to its starting position, simulating a bouncing motion.

Example: Create a bouncing ball effect for a simple circle icon. This effect makes the icon appear as if it's bouncing up and down.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=           "width=device-width, initial-scale=1.0">     <title>Document</title>     <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">     <style>         /* CSS will go here */         style.bounce-container {             text-align: center;             margin-top: 50px;         }          .fa-circle {             font-size: 48px;             color: blue;             animation: bounce 2s infinite;         }          @keyframes bounce {              0%,             20%,             50%,             80%,             100% {                 transform: translateY(0);             }              40% {                 transform: translateY(-30px);             }              60% {                 transform: translateY(-15px);             }         }     </style> </head>  <body>     <div class="bounce-container">         <i class="fas fa-circle"></i>     </div> </body>  </html> 

Output:

dskhjshkdl
Animated Bouncing Ball

Using Rotate Animation

This approach makes an icon continuously spin around in a circle. It uses keyframes to rotate the icon from 0 to 360 degrees.The icon rotates fully around its centre in a smooth, endless loop, creating a spinning effect.

Example: Create a rotating gear icon to simulate a loading effect.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=           "width=device-width, initial-scale=1.0">     <title>Document</title>     <link rel="stylesheet" href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">     <style>         /* CSS will go here */          style.rotate-container {             text-align: center;             margin-top: 50px;         }          .fa-cog {             font-size: 48px;             color: gray;             animation: rotate 2s linear infinite;         }          @keyframes rotate {             from {                 transform: rotate(0deg);             }              to {                 transform: rotate(360deg);             }         }     </style>  </head>  <body>     <div class="rotate-container">         <i class="fas fa-cog"></i>     </div> </body>  </html> 

Output:

Recording-2024-08-05-115256
Animated Rotating Gear

Conclusion

Using CSS animations with icons can greatly enhance the visual appeal of our website. By this we can easily add animated effects to our icons, making them more engaging and interactive. Experiment with different animations and styles to find what works best for our design.


Next Article
How to Create Jumping Text 3D Animation Effect using CSS ?
author
tanmoymishra
Improve
Article Tags :
  • Web Technologies
  • CSS
  • CSS-Questions

Similar Reads

  • How to use Animation and Transition Effects in CSS ?
    With the help of CSS, you may design impressive visual effects for your website. Animation and transition effects are two common ways to add animation and visual effects to a web page. By attracting users' attention and directing them through your material, these effects may make your website more d
    4 min read
  • How to make Animated Click Effect using HTML CSS and JavaScript ?
    In this article, we will see how to make an Animated Click Effect using HTML CSS, and JavaScript. We generally see animations on modern websites that are smooth and give users a good experience. Here, we will see when the user clicks on the button only then some animation would appear. The animation
    3 min read
  • How to create a marquee effect using CSS ?
    In this article, we will be creating the marquee effect by using HTML and CSS. This effect can be created by using the <marquee> tag in HTML, but we will not use this tag as it is not widely used nowadays. We will create and design a marquee effect by using the CSS classes and styling properti
    2 min read
  • How to make Animated Click Effect using Tailwind CSS & JavaScript ?
    It refers to the technique of implementing animations that respond to user clicks, utilizing the Tailwind CSS for styling and layout, and JavaScript for adding dynamic behavior to the elements. This enhances user engagement and improves the overall user experience of the websites. Table of Content U
    2 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
  • How to Add Visual Effects to Images using CSS?
    CSS is most useful for adding visual effects to images, enhancing the overall user experience. By using CSS properties like filter, transform, and transition, you can create dynamic and engaging effects that respond to user interactions. In this article, we will explore examples showcasing the visua
    2 min read
  • How to Animate Rainbow Heart from a Square using CSS ?
    In this article, you will learn how to make a magical heart using only CSS. Animations in CSS are a widely fascinating part of CSS. We will be creating a heart that changes color every 3 seconds. We will be creating the animation in two steps. 1. Building the heart: In this step we will be building
    3 min read
  • How to make photo sliding effect using HTML and CSS ?
    It is an easy and amazing animation effect created with HTML and CSS, where the photos are moving horizontally one by one like a roller. When the mouse pointer comes upon the photo then the specific photo stops moving. Approach: The basic idea of these animation comes from the hover effect of CSS an
    5 min read
  • How to create a Menu Icon using CSS ?
    The Menu Icon is mostly used on smaller screens, there's limited space to display a full navigation menu. A menu icon helps in hiding the navigation items initially and revealing them when the user needs them. In this article, we will see how To Create a Menu Icon using CSS. There are many ways to c
    3 min read
  • How to create icon hover effect using CSS ?
    To style an icon's color, size, and shadow using CSS, use the color property to set the icon's color, font size to adjust its size, and text-shadow or box-shadow for adding shadow effects, creating a visually appealing and dynamic look. Using: hover Pseudo-ClassUsing the: hover pseudo-class, you can
    2 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