Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Fade In Tooltip with CSS Animation
CSS tooltip animations provide a smooth visual experience when displaying helpful information. A fade-in effect creates an elegant transition as the tooltip becomes visible on hover. This technique combines CSS transitions with hover states to create professional-looking tooltips.
Syntax
.tooltip .tooltip-text {
opacity: 0;
transition: opacity duration;
}
.tooltip:hover .tooltip-text {
opacity: 1;
}
Example
The following example creates a fade-in tooltip that appears when you hover over the text −
<!DOCTYPE html>
<html>
<head>
<style>
.mytooltip {
position: relative;
display: inline-block;
margin: 50px;
padding: 10px 15px;
background-color: #f0f0f0;
border: 1px solid #ccc;
border-radius: 4px;
cursor: pointer;
}
.mytooltip .mytext {
visibility: hidden;
width: 140px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
top: -45px;
left: 50%;
margin-left: -70px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}
.mytooltip .mytext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #333 transparent transparent transparent;
}
.mytooltip:hover .mytext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<div class="mytooltip">Hover over me
<span class="mytext">Fade-in tooltip!</span>
</div>
</body>
</html>
A gray button-like element with "Hover over me" text appears. When you hover over it, a dark tooltip with "Fade-in tooltip!" smoothly fades in above the element with a small arrow pointing down.
Key Properties
| Property | Purpose |
|---|---|
opacity |
Controls the transparency (0 = invisible, 1 = fully visible) |
transition |
Defines the smooth animation effect and duration |
visibility |
Shows or hides the element from the document flow |
::after |
Creates the arrow pointing from tooltip to the trigger element |
Conclusion
Fade-in tooltips enhance user experience by providing smooth visual feedback. The combination of opacity, transition, and :hover pseudo-class creates an elegant animation effect that draws attention without being jarring.
Advertisements
