Building Tooltip using CSS

A tooltip is used to set extra information. This is visible on the web page when visitor moves the mouse pointer over an element.

Following is the code for building tooltip using CSS −


 Live Demo

<!DOCTYPE html>
body {
   font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   text-align: center;
.toolTip {
   position: relative;
   display: inline-block;
   border-bottom: 3px double rgb(255, 0, 0);
.toolTip .toolText {
   visibility: hidden;
   width: 160px;
   background-color: #721cd4;
   color: #fff;
   text-align: center;
   border-radius: 6px;
   padding: 5px 0;
   position: absolute;
   top: -35px;
   left: -10px;
   z-index: 1;
.toolTip:hover .toolText {
   visibility: visible;
<h1>Css tooltip example</h1>
<div class="toolTip">
Hover over me
<span class="toolText">Some toolTip text</span>
<h2>Hover over the above text to see the tooltip</h2>


The above code will produce the following output −

On hovering above the “Hover over me” text −

Updated on: 07-May-2020


Kickstart Your Career

Get certified by completing the course

Get Started