Creating Tooltips with CSS


Show tooltips on hover using only CSS.

Source Code

.tooltip {
    position: relative;
    display: inline-block;
}
.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background-color: black;
    color: white;
    padding: 5px;
    border-radius: 5px;
    opacity: 0;
    transition: opacity 0.3s;
    visibility: hidden;
}
.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments