Rubber Band Text animation using HTML and CSS
Last Updated :
19 Jun, 2024
Rubber Band Text animation refers to a CSS effect where text appears to stretch and bounce back, resembling a rubber band. This playful animation adds dynamic visual interest to text, often achieved using CSS keyframes for smooth, elastic-like transitions on hover or load.
Creating Structure: In this section, we will just use the HTML to create the text string.
- HTML Setup: Create a basic HTML structure with <!DOCTYPE html>, meta charset, and title for the document.
- Text Container: Add a <div> with id="text" containing an <h1> heading and a <b> tag for instructions.
- CSS for Animation: Define and apply CSS for styling and @keyframes animation for the rubber band effect.
Example: Here we are following the above-mentioned approach.
HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>Rubber Band Text Animation</title>
</head>
<body>
<div id="text">
<h1>GeeksforGeeks</h1>
<b>Hover over on the text</b>
</div>
</body>
</html>
Designing Structure: In this section we will design the structure to make the created text string rubbery.
- CSS Code: In this section we will create the animation effect using CSS animations, we will use the @keyframes rule to specify the animation code. We will use the transform property to produce the animation
- Initial State: At 0%, the text starts at its normal size with transform: scale(1, 1).
- Stretch and Squash: At 25%, the text stretches horizontally and squashes vertically with transform: scale(1.3, 0.6).
- Return to Normal: At 50% and 100%, the text slightly adjusts then returns to its original size with transform: scale(1, 1).
CSS
body {
margin: 0;
padding: 0;
font-family: serif;
}
#text {
position: relative;
margin-top: 100px;
text-align: center;
}
h1 {
color: green;
}
#text:hover {
animation: effect linear 1s;
}
@keyframes effect {
0% {
transform: scale(1, 1);
}
25% {
transform: scale(1.3, 0.6);
}
50% {
transform: scale(1.1, 0.9);
}
100% {
transform: scale(1, 1);
}
}
Final Solution: It is the combination of the above two code sections.
HTML
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<title>Rubber Band Text Animation</title>
<style>
body {
margin: 0;
padding: 0;
font-family: serif;
}
#text {
position: relative;
margin-top: 100px;
text-align: center;
}
h1 {
color: green;
}
#text:hover {
animation: effect linear 1s;
}
@keyframes effect {
0% {
transform: scale(1, 1);
}
25% {
transform: scale(1.3, 0.6);
}
50% {
transform: scale(1.1, 0.9);
}
100% {
transform: scale(1, 1);
}
}
</style>
</head>
<body>
<div id="text">
<h1>GeeksforGeeks</h1>
<b>Hover over on the text</b>
</div>
</body>
</html>
Output:

The rubber band text animation is an engaging CSS effect where text stretches and bounces back, resembling a rubber band. By combining HTML structure and CSS keyframes animation, we create a dynamic visual interest for text elements. This animation enhances user experience by adding a playful and interactive element to web design. Through the use of CSS animations and the @keyframes rule, we can easily implement this effect, making text appear elastic and responsive on hover or load. This guide demonstrates a step-by-step approach to achieving this popular effect, providing both the HTML structure and CSS design necessary for a smooth, rubbery animation.
Similar Reads
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 Typewriter Animation using HTML and CSS ? A typewriter animation simulates the appearance of text being typed out letter by letter, using only HTML and CSS. This effect is a simple yet eye-catching way to bring dynamic text to life on a website, capturing attention without the need for JavaScript. It's a great technique to make key text ele
6 min read
How to Create Text Color Animation using HTML and CSS ? The text color can be changed according to the programmerâs choice using CSS @keyframes rule. In this article, we will see how to create text color animation using HTML and CSS. Preview:Approach:Create an HTML file with a centered <div> containing an <h2> element.Use CSS to reset default
1 min read
How to create a progress bar animation using HTML and CSS ? In this mini Web Development project we will utilize CSS animations and create a progress bar using them. The progress bar will start from zero and go to a certain extent as we want. The progress bar is basically showing the expertise of a programmer in different languages in animated form. Prerequi
3 min read
How to make a Animated Table using HTML and CSS ? Table is an arrangement of data in rows and columns, or possibly in a more complex structure. Tables are widely used in communication, research, and data analysis. In this article, we are going to create a Table with animation over its columns. We are going to implement it using HTML and CSS. Approa
3 min read
Create a Tooltip Button Animation using HTML and CSS The Tooltip Animation can be implemented to display additional information about a user or profile when hovering over a designated button or icon. Animations, like tooltips and button animations, add a layer of interactivity to the user interface, making the experience more engaging and enjoyable.Pr
4 min read