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
  • Tailwind CSS Tutorial
  • Tailwind Interview Questions
  • Tailwind Layout
  • Tailwind Flexbox
  • Tailwind Grid
  • Tailwind Alignment
  • Tailwind Spacing
  • Tailwind Sizing
  • Tailwind Typography
  • Tailwind Backgrounds
  • Tailwind Borders
  • Tailwind Effects
  • Tailwind Filters
  • Tailwind Tables
  • Tailwind Transitions and Animation
  • Tailwind Transforms
  • Tailwind Interactivity
  • CSS Frameworks
  • Web Technology
Open In App
Next Article:
Tailwind CSS Flex Grow
Next article icon

Tailwind CSS Hover Effects

Last Updated : 03 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

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 Content

  • Simple Hover Effect (Background color change)
  • Scale on Hover
  • Shadow Effect on Hover (Card Shadow)

Simple Hover Effect (Background color change)

  • First, create a basic HTML structure.
  • Then include the Tailwind CSS CDN link in the <head> section to apply Tailwind CSS classes.
  • Inside the <body>, add a button element and apply Tailwind classes for styling (e.g., bg-blue-500, text-white, py-2, px-4, rounded).
  • For the hover effect use the "hover:bg-blue-700" class to change the background color on hover.

Example: This example shows the implementation of above explained approach

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=           "width=device-width, initial-scale=1.0">     <title>Simple Hover Effect</title>     <script src="https://cdn.tailwindcss.com"></script> </head>  <body class="flex flex-col items-center              justify-center h-screen bg-gray-100">     <h1 class="text-2xl font-bold mb-6 text-green-600">       Simple Hover Effect     </h1>     <button class="bg-blue-500 text-white font-bold                     py-2 px-4 rounded hover:bg-blue-700                    hover:text-gray-200">                 Hover me     </button> </body>  </html> 

Output:

Scale on Hover

  • First, create a basic HTML structure for your need.
  • Then include the Tailwind CSS CDN link in the <head> section to apply Tailwind CSS classes.
  • And inside the <body>, add a button element and apply Tailwind classes for styling (e.g., bg-blue-500, text-white, py-2, px-4, rounded).
  • Use the "transform" class to allow transformations, and use "hover:scale-105" for scaling the button on hover. Include transition, duration-300, and ease-in-out for smooth animation.

Example: This example shows the implementation of above explain approach

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=           "width=device-width, initial-scale=1.0">     <title>Scale on Hover</title>     <script src="https://cdn.tailwindcss.com"></script> </head>  <body class="flex flex-col items-center              justify-center h-screen bg-gray-100">     <h1 class="text-2xl font-bold mb-6                 text-green-600">       Scale on Hover Effect     </h1>     <button         class="bg-green-500 text-white font-bold                py-2 px-4 rounded transform hover:scale-105                transition duration-300 ease-in-out">         Hover me     </button> </body>  </html> 

Output:

Shadow Effect on Hover (Card Shadow)

  • First, create a basic HTML structure for your need.
  • Then include the Tailwind CSS CDN link in the <head> section to apply Tailwind CSS classes.
  • And inside the <body>, create a card using a div with the "max-w-sm", "rounded", "overflow-hidden", and "shadow-lg classes". Also add an image and text content inside the card for attract user attention.
  • Then use the "hover:shadow-2xl" class to increase the shadow intensity on hover.

Example: This example shows the implementation of above explain approach

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta name="viewport" content=           "width=device-width, initial-scale=1.0">     <title>Shadow Effect on Hover</title>     <script src= "https://cdn.tailwindcss.com"></script> </head>  <body class="flex flex-col items-center justify-center              h-screen bg-gray-100">     <h1 class="text-2xl font-bold mb-6                text-green-600">       Hover Shadow Effect on Card     </h1>     <div class="max-w-sm rounded overflow-hidden                  shadow-lg hover:shadow-2xl transition                 duration-300 ease-in-out">         <img class="w-full"             src= "https://media.geeksforgeeks.org/wp-content/uploads/20230602174859/OpenAI-Python-Tutorial-.webp"             alt="Sample Image">         <div class="px-6 py-4">             <div class="font-bold text-xl mb-2">               Card Title             </div>             <p class="text-green-600 text-base">                 This is a sample card with hover shadow effect.                 Hover over the card to see the effect.             </p>         </div>     </div> </body>  </html> 

Output:


Next Article
Tailwind CSS Flex Grow
author
skaftafh
Improve
Article Tags :
  • Web Technologies
  • Tailwind CSS

Similar Reads

  • Tailwind CSS Pointer Events
    This class accepts lots of value in tailwind CSS in which all the properties are covered in class form. This class is used to specify whether elements show to pointer events or not show on the pointer. In CSS, we do that by using the CSS pointer-events property. Pointer Events Classes: pointer-event
    1 min read
  • Tailwind CSS Cursor
    Tailwind CSS offers various utility classes to set the mouse cursor appearance when pointing at an element. These classes correspond to the CSS cursor property, allowing you to quickly specify the cursor type without writing custom CSS Cursor Classes:ClassDescriptioncursor-autoDefault cursor set by
    2 min read
  • Tailwind CSS Filter
    The filter class is used to set the visual effect of an element. This class is mostly used in image content. In CSS, we do that by using the CSS filter property. Tailwind CSS newly added feature filter in 2.1 version. Filter Classes: filter: This class is used to enable filters.filter-none: This cla
    1 min read
  • Tailwind CSS Overflow
    This overflow is for controlling how an element content is handled that is too large for the container. It tells whether to clip content or add scroll bars. This class accepts more than one value in Tailwind CSS. It is the alternative to the CSS Overflow property. There is a separate property in CSS
    7 min read
  • Tailwind CSS Flex Grow
    The CSS flexbox is a vital feature to develop the frontend, there is two flex-grow available in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex grow Property for the fast development of the front-end. This class specifies how much the item will grow co
    2 min read
  • Tailwind CSS Effects Complete Reference
    Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the buildings blocks that you need. Tailwind CSS Effects control the effects on elements. that provide classes to apply effects on elements like box-shadow, opacity/transparency. Tailwind CSS Class Description Box S
    1 min read
  • Tailwind CSS Fixed NavBar
    In this article, we'll see how to fix a navbar in Tailwind CSS. A navigation bar (navbar) is a user interface element used for website menu navigation and links, we are using fixed class and sticky class to fix the nav bar at the top of the page. We will explore two approaches to creating a fixed na
    5 min read
  • Tailwind CSS Invert
    The invert class is an inbuilt function that is used to apply a filter to the image to set the invert version of the color of the sample image. In CSS, we do that by using the CSS invert() Function. Invert Classes: invert-0: This class is used to represent the original color.invert: This class is us
    1 min read
  • How to Modify Hover Effect using Tailwind CSS ?
    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 yo
    3 min read
  • Tailwind CSS Flex
    The CSS flexbox is a vital feature to develop the frontend, there is four flex available in tailwind CSS all the properties are covered as in class form. It is the alternative of CSS flex Property for fast development of front-end. It is used to set the length of flexible items. The flex class is mu
    5 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