In this section, we will learn how to use text animation in Tailwind CSS. To create a text animation without defining custom keyframes in CSS, you can leverage the existing animation utilities in Tailwind along with some creative use of other utility classes. Here’s a step-by-step guide on how to achieve this.
Utilize Tailwind’s Built-in Animation Utilities: Tailwind provides some basic animation classes, such as animate-spin or animate-ping, but these might not be directly suitable for text animations. However, you can use them as a starting point.
Combine with Transform Utilities: You can combine the animation utilities with transform utilities (like scale, rotate, translate, etc.) to create more interesting effects. For example, you might use scale to create a popping effect.
Tailwind CSS Simple Popping Text Animation.
<div class="animate-pulse">
<span class="text-2xl font-bold transform scale-90 hover:scale-100 transition-transform duration-300 ease-in-out">
Animated Text
</span>
</div>
Tailwind CSS Popping Color Text Animation.
<div class="animate-pulse">
<span class="text-2xl font-bold text-purple-500 hover:text-purple-700 transition-colors duration-300">
Animated Text
</span>
</div>
Tailwind CSS Bouncing Text Animation.
<div class="animate-bounce p-4">
<span class="text-4xl font-bold text-orange-500">
Bouncing Text
</span>
</div>
<div class="animate-bounce bg-green-500 max-w-sm p-4">
<span class="text-4xl font-bold text-white">
Bouncing Text
</span>
</div>
Tailwind CSS custom keyframe Text Animation.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Animation with Tailwind CSS</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
@keyframes slide-in {
from {
transform: translateX(-100%);
}
to {
transform: translateX(0);
}
}
.animate-slide-in {
animation: slide-in 1s ease-out;
}
</style>
</head>
<body class="flex justify-center items-center h-screen bg-gray-100">
<h1 class="text-4xl font-bold animate-slide-in">Hello, Tailwind CSS!</h1>
</body>
</html>