CHAPTER 57
CSS Tooltips
Learn how to create small information popups using CSS.
01. What is CSS Tooltips?
A tooltip displays additional information when a user interacts with an element.
CSS can create basic tooltips using pseudo-elements.
Tooltips should remain accessible and understandable.
02. Syntax
.tooltip:hover .tooltip-text {
visibility: visible;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
.tooltip {
position: relative;
display: inline-block;
padding: 15px;
background: #2563eb;
color: white;
}
.tooltip-text {
visibility: hidden;
position: absolute;
bottom: 120%;
left: 50%;
transform: translateX(-50%);
background: #020617;
color: white;
padding: 8px 12px;
border-radius: 6px;
white-space: nowrap;
}
.tooltip:hover .tooltip-text {
visibility: visible;
}
</style>
</head>
<body>
<div class="tooltip">
Hover Me
<span class="tooltip-text">
CSS Information
</span>
</div>
</body>
</html>
04. Important Points
✓
The tooltip parent commonly uses position: relative.
✓
The tooltip itself can use position: absolute.
✓
z-index may be required.
✓
Tooltips should not hide essential information.
05. Common Mistakes
⚠
Making tooltip text impossible to read.
⚠
Using tooltips for essential instructions.
⚠
Making tooltips unavailable to keyboard users.
06. Real World Use
Tooltips are used in dashboards, icon buttons, software interfaces and educational interfaces.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create a Tooltip
Create a button that displays a small tooltip when the user hovers over it.