Design a Letter Hover Effect using HTML CSS and JavaScript Last Updated : 25 Sep, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we will learn to implement the bouncing letter hover effect using simple HTML, CSS, and JavaScript. HTML is used to create the structure of the page, CSS is used to set the styling and JavaScript is used for animation. Approach to Create the Bouncing Letter Hover EffectHTML Code: To achieve a dynamic bouncing text effect, start by enclosing each letter of a <h1> heading in <span> tags. This letter-level control, combined with CSS and JavaScript, results in an engaging bounce animation, perfect for grabbing attention in headers, banners, and other emphasized text.CSS Code: The .bounce class selector applies the "bounce" keyframes animation to an HTML element, specifically to <span> elements wrapped around heading letters. Elements with this class showcase the animation behavior. JavaScript Code: In this code, <span> elements within the "bouncing-letters" container are targeted. When these <span> elements are hovered over, the bounce() function is triggered, passing the hovered element. bounce() ensures smooth animation. It checks if the <span> doesn't have the "bounce" class to avoid repeated animations. If not present, it adds the "bounce" class for the CSS animation. Using setTimeout(), the class is removed after 1 second, restoring the element to its original state.Example: This example shows the implementation of the above approach. HTML <!DOCTYPE html> <html lang="en"> <head> <title> Bouncing Letter Hover Effect </title> <style> body { background-color: rgba(175, 224, 175, 255); } h1 { font-family: sans-serif; font-size: 110px; text-align: center; color: #318D45; margin-top: 250px; } .bounce { animation-name: bounce; } .bouncing-letters span { animation-timing-function: linear; animation-duration: 1s; animation-iteration-count: 1; display: inline-block; } .bouncing-letters span:hover { color: whitesmoke; } @keyframes bounce { 20%, 50%, 80%, to { transform: scale(1, 1); } 40% { transform: scale(1.75, 0.65); } 45% { transform: scale(1.75, 0.65); } 70% { transform: scale(1.25, 0.75); } 90% { transform: scale(1.15, 0.85); } } </style> </head> <body> <h1 class="bouncing-letters" style="letter-spacing:0.3px;"> <span>G</span> <span>e</span> <span>e</span> <span>k</span> <span>s</span> <span>F</span> <span>o</span> <span>r</span> <span>G</span> <span>e</span> <span>e</span> <span>k</span> <span>s</span> </h1> <script> document.querySelectorAll(".bouncing-letters>span") .forEach((element) => { element.addEventListener("mouseover", (e) => bounce(e.target)); }); function bounce(letter) { if (!letter.classList.contains("bounce")) { letter.classList.add("bounce"); setTimeout( function () { letter.classList.remove("bounce"); }, 1000 ); } } </script> </body> </html> Output: Output Comment More info A adiityachand Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like