One tooltip for a whole toolbar: it glides under whichever button you hover while its label rolls to the new name. :has() sets an --x index per button, and the labels are a clipped strip.
Also known as: toolbar tooltip css, shared tooltip that follows hover, editor toolbar hint.
<span class="tip-sliding-toolbar" role="toolbar" aria-label="Text formatting"> <button type="button" aria-label="Bold"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M7 5h5.5a3.5 3.5 0 0 1 0 7H7zM7 12h6.5a3.5 3.5 0 0 1 0 7H7z"/></svg></button> <button type="button" aria-label="Italic"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 5h8M6 19h8M14.5 5l-5 14"/></svg></button> <button type="button" aria-label="Link"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/></svg></button> <button type="button" aria-label="Comment"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 19V6.5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H8.5z"/></svg></button> <span class="tip-sliding-toolbar-tip" role="tooltip" aria-hidden="true"><span class="tip-sliding-toolbar-labels"><span>Bold</span><span>Italic</span><span>Link</span><span>Comment</span></span></span> </span>
.tip-sliding-toolbar {
--c: var(--tip-color, #3b82f6);
font-size: var(--tip-size, 16px);
position: relative;
display: inline-flex;
--x: 0;
margin-bottom: 2.5em; /* room for the tooltip in this preview */
padding: 0.3em;
border: 1px solid color-mix(in srgb, var(--c) 25%, transparent);
border-radius: 0.75em;
background: color-mix(in srgb, var(--c) 7%, transparent);
}
/* which button is under the pointer or focused: 0, 1, 2 or 3 */
.tip-sliding-toolbar:has(button:nth-of-type(2):hover, button:nth-of-type(2):focus-visible) { --x: 1; }
.tip-sliding-toolbar:has(button:nth-of-type(3):hover, button:nth-of-type(3):focus-visible) { --x: 2; }
.tip-sliding-toolbar:has(button:nth-of-type(4):hover, button:nth-of-type(4):focus-visible) { --x: 3; }
.tip-sliding-toolbar button {
display: grid;
place-items: center;
width: 2.4em;
height: 2.4em;
padding: 0;
border: 0;
border-radius: 0.5em;
background: transparent;
color: color-mix(in srgb, currentColor 70%, transparent);
cursor: pointer;
transition: background-color 0.2s ease, color 0.2s ease;
}
.tip-sliding-toolbar button:hover {
background: color-mix(in srgb, var(--c) 16%, transparent);
color: var(--c);
}
.tip-sliding-toolbar svg {
width: 1.2em;
height: 1.2em;
}
.tip-sliding-toolbar button:focus-visible {
outline: 2px solid var(--c);
outline-offset: 2px;
}
.tip-sliding-toolbar-tip {
position: absolute;
top: calc(100% + 0.6em);
/* the first button's center: 0.3em of padding plus half of 2.4em */
left: 1.5em;
z-index: 10;
width: 5.4em;
padding: 0.15em 0;
border-radius: 0.45em;
background: color-mix(in srgb, var(--c) 14%, #0f172a);
box-shadow: 0 0.5em 1em -0.4em rgb(0 0 0 / 0.5);
color: #fff;
font-family: system-ui, sans-serif;
text-align: center;
opacity: 0;
visibility: hidden;
pointer-events: none;
/* one button is 2.4em wide, so each step of --x moves 2.4em */
transform: translate(calc(var(--x) * 2.4em - 50%), -0.3em);
transition: opacity 0.18s ease, transform 0.35s cubic-bezier(0.3, 1.3, 0.5, 1), visibility 0.35s;
}
.tip-sliding-toolbar-tip::before {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
width: 0.55em;
height: 0.55em;
background: inherit;
transform: translate(-50%, 50%) rotate(45deg);
}
.tip-sliding-toolbar-labels {
display: block;
height: 1.5em;
overflow: hidden;
}
.tip-sliding-toolbar-labels span {
display: block;
font-size: 0.8em;
font-weight: 600;
line-height: 1.875; /* 1.5em of the toolbar's size */
transform: translateY(calc(var(--x) * -100%));
transition: transform 0.35s cubic-bezier(0.65, 0, 0.35, 1);
}
.tip-sliding-toolbar:hover .tip-sliding-toolbar-tip,
.tip-sliding-toolbar:focus-within .tip-sliding-toolbar-tip {
opacity: 1;
visibility: visible;
transform: translate(calc(var(--x) * 2.4em - 50%), 0);
}
@media (prefers-reduced-motion: reduce) {
.tip-sliding-toolbar, .tip-sliding-toolbar *, .tip-sliding-toolbar::before, .tip-sliding-toolbar::after, .tip-sliding-toolbar *::before, .tip-sliding-toolbar *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--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.