/* styles.css */
.image-container {
display: inline-block;
position: relative;
}
.tooltip {
display: none;
position: absolute;
background-color: rgba(0, 0, 0, 0.8);
color: white;
padding: 5px;
border-radius: 3px;
font-size: 14px;
bottom: 100%;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
}
.image-container:hover .tooltip {
display: block;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="script.js" defer></script>
<title>Image Tooltip</title>
</head>
<body>
<div class="image-container">
<img src="your-image-source.jpg" alt="Your Image">
<div class="tooltip">Your Tooltip Text</div>
</div>
</body>
</html>
The .tooltip element is positioned absolutely within the .image-container. The bottom property is set to 100% so that it appears just above the image, and the left property is set to 50% to horizontally center the tooltip. The transform: translateX(-50%) ensures that the tooltip is centered precisely. The display: none style hides the tooltip by default, and the tooltip is shown on hover using .image-container:hover .tooltip.