JSFiddle - React, Tailwind, and code Playground
HTML
<h2>Tooltip</h2>
<p>Move the mouse over the text below:</p>
<div class="tooltip" tooltip="This is a tooltip">
Hover over me
</div>
CSS
body {
padding: 50px;
}
.tooltip {
position: relative;
display: inline-block;
border-bottom: 1px dotted black;
z-index: 2;
cursor: pointer;
}
[tooltip]::before,
[tooltip]::after {
position: absolute;
bottom: 125%;
left: 50%;
visibility: hidden;
opacity: 0;
pointer-events: none;
transition: opacity 1s;
}
[tooltip]::before {
content: attr(tooltip);
/* Cosmetics */
color: #fff;
background-color: #555;
width: 120px;
text-align: center;
padding: 5px 0;
margin-bottom: 5px;
margin-left: -60px;
border-radius: 6px;
opacity: 0;
}
[tooltip]::after {
content: "";
/* This creates the indicators */
margin-left: -5px;
border-top: 5px solid #555;
border-right: 5px solid transparent;
border-left: 5px solid transparent;
}
[tooltip]:hover::before,
[tooltip]:hover::after {
visibility: visible;
opacity: 1;
}