Menu Close

How To Create Tooltips Using Html And CSS

Tooltips

Here, we learn about how to create tooltips using html and css. Follow the below snippet to achieve this.

<!DOCTYPE html>
<html> 
<head>
    <title>How to create tooltips using html and css</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="style.css">
</head>  
<body>
    <h2>Tooltip</h2>
    <div class="tooltip">Hover over me
        <span class="tooltiptext">tooltip text</span>
    </div>
</body>
</html> 

Add the below stylesheet to the html file.

body {
    margin: 50px;
    font-family: Arial, sans-serif;
}
.tooltip {
    position: relative;
    display: inline-block;
    text-decoration: underline;
}
.tooltip .tooltiptext {
    visibility: hidden;
    width: 120px;
    background-color: #eeeddd;
    color: #000;
    text-align: center;
    border-radius: 6px;
    padding: 5px 0;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -60px;
    opacity: 0;
    transition: opacity 0.3s;
}
.tooltip .tooltiptext::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #eeeddd transparent transparent transparent;
}
.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
} 
Posted in CSS, HTML

You can also read...