CSS Tooltips
Build simple tooltips using ::before (tooltip box) and ::after (arrow) on a data-tooltip attribute, with no JavaScript required.
Build simple tooltips using ::before (tooltip box) and ::after (arrow) on a data-tooltip attribute, with no JavaScript required.
[data-tooltip] {
position: relative;
cursor: help;
}
[data-tooltip]::before {
content: attr(data-tooltip);
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
transform: translateX(-50%);
background: #333;
color: white;
padding: 4px 8px;
border-radius: 4px;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transition: opacity 0.2s;
}
[data-tooltip]:hover::before { opacity: 1; }
For accessibility, supplement CSS tooltips with aria-describedby pointing to a real hidden element for screen readers.