How to Modify Hover Effect using Tailwind CSS ?
Last Updated :
28 Apr, 2025
In Tailwind CSS, the term "modify hover" refers to changing the styles that are applied to an element when it is hovered over. With Tailwind CSS "hover" variation, you can quickly apply particular utility classes and custom classes to control how components appear when you hover over them, giving you flexibility in creating hover effects for your web application. In this article, we will see the different techniques to manipulate the hover effect with the help of Tailwind CSS.
Syntax:
<element class="base-class hover:modified-class">
Content
</element>
Where,
- base-class: This is the base utility class, which establishes the element's default style.
- hover :modified-class: This combines the hover variant and the modified-class. The modified class is applied when the element is hovered over.
Here, we have some common approaches to modifying hover in Tailwind CSS:
- Using utility classes
- Using custom classes
Approach 1: Using Utility Classes
The most straightforward approach is to use utility classes provided by Tailwind CSS. You can apply different utility classes to modify specific properties like background color, text color, padding, etc.
Example: In this example, we are using Tailwind CSS to create a centered heading and a button. The button changes its background color from blue to red when hovered over.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width,
initial-scale=1.0">
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet">
<title>
Tailwind CSS Hover Example
</title>
</head>
<body class="text-center">
<h1 class="text-green-600 text-5xl font-bold">
GeeksforGeeks
</h1>
<div class="flex justify-center items-center">
<button class="bg-blue-500 hover:bg-red-500
text-white font-bold py-2
px-4 rounded">
Hover me!
</button>
</div>
</body>
</html>
Output:

Approach 2: Using Custom Classes
Tailwind CSS also allows you to define custom classes and apply them to elements. You can define custom classes in your tailwind.config.js file and use them to modify hover effects.
Example: In this example, we will modify the code to include a custom class called customRed, which can define the custom class in your tailwind.config.js file as follows:
JavaScript
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
customRed: '#DE3163',
},
},
},
variants: {},
plugins: [],
};
HTML code: When a button is hovered over, the background color is changed to the custom red color specified in the configuration file by applying the hover:bg-customRed class to the button element. The border-blue-500 hover:border-customRed classes also change the button's border color.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport"
content="width=device-width,
initial-scale=1.0" />
<title>
Tailwind CSS Hover Effect Example
</title>
<link href=
"https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet" />
</head>
<body class="text-center">
<h1 class="text-5xl font-bold text-green-600
flex items-center justify-center">
GeeksforGeeks
</h1>
<div class="flex items-center justify-center">
<button class="rounded border border-blue-500
px-4 py-2 font-bold text-white opacity-75
transition-all duration-300 ease-in-out
hover:border-customRed hover:bg-customRed
hover:opacity-100">
Hello world!
</button>
</div>
</body>
</html>
Output:
Using custom classes by modifying config.jsÂ
Similar Reads
How to make Profile Card Hover Effect using CSS ? Almost all of us must have heard that 'the first impression is the last impression'. The profile card carries the most important details we should know about a person at the very first instant. A better impression attracts more traffic. So to engage more audience in a website it is very important to
3 min read
How to Change Image on Hover using Tailwind CSS? One common effect is changing an image when the user hovers over it. We use Tailwind CSS, a utility-first CSS framework, to accomplish this without any additional JavaScript logic for the hover effect. By utilizing Tailwind's built-in classes we can create smooth transitions between two images where
2 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
How to create image overlay hover slide effects using CSS ? In this article, we will learn how to make image overlay hover slide effects using CSS. When the users hover over the image, a smooth sliding overlay effect occurs. This technique gives a visual appeal with interactivity, making your website more interactive.Table of ContentFull Width Slide-In Text
4 min read
Tailwind CSS Hover Effects A hover effect is a visual change that occurs when a user moves their mouse pointer over an element on a webpage. We can achieve a hover effect by Tailwind CSS built-in prefix modifier called "hover: ".These are the following ways to use hover:Table of ContentSimple Hover Effect (Background color ch
3 min read
How to change the width on hover using Tailwind CSS ? In this article, we will change the width on hover using Tailwind. There is no inbuilt method in Tailwind, so you have to customize the tailwind.config.js file. Let's discuss the whole process further in this article.By default, tailwind CSS only generates responsive variants for width utilities. To
3 min read
How to use hover, focus and active variants in Tailwind CSS ? In this article, we will see how to use hover, focus, and active variants in Tailwind CSS. Tailwind CSS uses the Hover, Focus, and Active variants to style an element when the user mouses move over it, focuses it, or actively clicks/tapped it. These variants allow you to create interactive and dynam
4 min read
How to apply Hover Effect in CSS? The :hover pseudo-class in CSS is used for styling when an element is hovered over by a cursor. Syntaxa:hover { // CSS Styles...}HTML<!DOCTYPE html> <html> <head> <style> .hover-button { background-color: #4CAF50; padding: 15px 30px; font-size: 16px; cursor: pointer; } .hover
1 min read
Underline Hover Animation Effect using Tailwind CSS The Tailwind CSS underline animation is a visual effect that can be added to any text or heading or a specific word in the web page using the Tailwind CSS utility framework. The basic function of this effect is this creates an underline animation from left to right with a smooth transition, in simpl
3 min read
How to Make Floating Card Effect in Tailwind CSS? Floating card effect using Tailwind CSS is fun to make and explore. It is basically all about using the classes of Tailwind CSS to create cards when hovered upon have a floating effect, such that they are replaced from their position, either get transformed, or move up or down in their positions. we
2 min read