Coding⏱️ 2 min read📅 2026-06-03

How to Fix: What is the opposite of :hover (on mouse leave)?

CSS animation opposite to :hover using only CSS.

Quick Answer: Use the :focus pseudo-class with a negative value for the hover state, or utilize the :active pseudo-class in conjunction with the :not() selector.

To achieve the opposite effect of :hover, you can use the :not(:hover) pseudo-class in CSS. This will apply styles when the mouse is not hovering over the element.

🛑 Root Causes of the Error

  • The issue arises because :hover only applies styles when the mouse is hovering over an element, but not when it's leaving.

🚀 How to Resolve This Issue

Method 1: Using :not(:hover)

  1. Step 1: Add the :not(:hover) pseudo-class to your CSS rule.

Method 2: Using :active

  1. Step 1: Add the :not(:hover) pseudo-class to your CSS rule.

🎯 Final Words

By using either :not(:hover) or :active, you can create the opposite effect of :hover and achieve a smooth animation when the mouse leaves an element.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions