The standard tooltip: a dark bubble above the button with a small arrow, fading in as it rises into place. The arrow is a rotated square half tucked under the bubble.
Also known as: css tooltip with arrow, tooltip on hover css, tailwind tooltip.
<span class="tip-top-arrow"> <button type="button" aria-describedby="tip-top-arrow-tip">Share</button> <span class="tip-top-arrow-tip" id="tip-top-arrow-tip" role="tooltip">Share with your team</span> </span>
.tip-top-arrow {
--c: var(--tip-color, #3b82f6);
font-size: var(--tip-size, 16px);
position: relative;
display: inline-flex;
}
.tip-top-arrow button {
display: inline-flex;
align-items: center;
gap: 0.4em;
padding: 0.6em 1.2em;
border: 0;
border-radius: 0.5em;
background: var(--c);
color: #fff;
font: 600 1em system-ui, sans-serif;
cursor: pointer;
}
.tip-top-arrow button:focus-visible {
outline: 2px solid var(--c);
outline-offset: 2px;
}
.tip-top-arrow-tip {
position: absolute;
bottom: calc(100% + 0.7em);
left: 50%;
z-index: 10;
padding: 0.45em 0.75em;
border-radius: 0.4em;
background: #1e293b;
box-shadow: 0 0.4em 1em -0.3em rgb(0 0 0 / 0.45);
color: #fff;
font: 500 0.85em/1.3 system-ui, sans-serif;
white-space: nowrap;
opacity: 0;
visibility: hidden;
pointer-events: none;
transform: translate(-50%, 0.4em);
transition: opacity 0.18s ease, transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0.25s;
}
/* the arrow: a rotated square, half hidden under the bubble */
.tip-top-arrow-tip::before {
content: "";
position: absolute;
top: 100%;
left: 50%;
width: 0.6em;
height: 0.6em;
background: inherit;
transform: translate(-50%, -50%) rotate(45deg);
}
.tip-top-arrow:hover .tip-top-arrow-tip,
.tip-top-arrow:focus-within .tip-top-arrow-tip {
opacity: 1;
visibility: visible;
transform: translate(-50%, 0);
}
@media (prefers-reduced-motion: reduce) {
.tip-top-arrow, .tip-top-arrow *, .tip-top-arrow::before, .tip-top-arrow::after, .tip-top-arrow *::before, .tip-top-arrow *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}The same effect using Tailwind utility classes. No custom CSS or config needed.
<span class="group relative inline-flex"> <button type="button" aria-describedby="tooltip-share" class="rounded-lg bg-blue-500 px-4 py-2 font-semibold text-white focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-500">Share</button> <span id="tooltip-share" role="tooltip" class="pointer-events-none invisible absolute bottom-[calc(100%+0.6rem)] left-1/2 z-10 -translate-x-1/2 translate-y-1.5 whitespace-nowrap rounded-md bg-slate-800 px-3 py-1.5 text-sm font-medium text-white opacity-0 shadow-lg transition-all duration-200 ease-out before:absolute before:left-1/2 before:top-full before:h-2 before:w-2 before:-translate-x-1/2 before:-translate-y-1/2 before:rotate-45 before:bg-inherit before:content-[''] group-hover:visible group-hover:translate-y-0 group-hover:opacity-100 group-focus-within:visible group-focus-within:translate-y-0 group-focus-within:opacity-100">Share with your team</span> </span>
--tip-color on the element or a parent.
Currently previewing #3b82f6.--tip-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.