A terminal button whose tooltip types its command out one character at a time behind a blinking block cursor. A steps() animation on a ch-based width does the typing.
Also known as: typing tooltip css, terminal tooltip on hover, typewriter hover text.
<button class="hfx-tooltip-typewriter" aria-label="Open terminal"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4" width="18" height="16" rx="2.5"/><path d="m7.5 9.5 3 2.5-3 2.5M12.5 15h4"/></svg> <span class="hfx-tooltip-typewriter-tip"><span>npm run dev</span></span> </button>
.hfx-tooltip-typewriter {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 2.75em;
height: 2.75em;
padding: 0;
border: 0;
border-radius: 0.65em;
background: var(--c);
color: #fff;
cursor: pointer;
}
.hfx-tooltip-typewriter > svg { width: 1.35em; height: 1.35em; }
.hfx-tooltip-typewriter-tip {
position: absolute;
bottom: calc(100% + 0.7em);
left: 50%;
display: flex;
align-items: center;
box-sizing: content-box;
width: 14ch;
padding: 0.5em 0.8em;
border-radius: 0.5em;
background: #0f172a;
box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 40%, transparent), 0 0.5em 1.2em -0.4em rgba(0, 0, 0, 0.5);
color: color-mix(in srgb, var(--c) 45%, #fff);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.8em;
font-weight: 600;
line-height: 1.3;
white-space: nowrap;
opacity: 0;
pointer-events: none;
transform: translate(-50%, 0.4em) scale(0.92);
transform-origin: 50% 100%;
transition: opacity 0.15s ease, transform 0.25s cubic-bezier(0.3, 0.7, 0.4, 1);
}
.hfx-tooltip-typewriter-tip::before {
content: "$";
margin-right: 1ch;
opacity: 0.5;
}
.hfx-tooltip-typewriter-tip span {
width: 0;
overflow: hidden;
}
.hfx-tooltip-typewriter-tip::after {
content: "";
width: 0.6ch;
height: 1.15em;
margin-left: 0.1ch;
background: currentColor;
}
.hfx-tooltip-typewriter:is(:hover, :focus-visible) .hfx-tooltip-typewriter-tip {
opacity: 1;
transform: translate(-50%, 0) scale(1);
}
.hfx-tooltip-typewriter:is(:hover, :focus-visible) .hfx-tooltip-typewriter-tip span {
animation: hfx-tooltip-typewriter-type 0.8s steps(11) 0.2s both;
}
.hfx-tooltip-typewriter:is(:hover, :focus-visible) .hfx-tooltip-typewriter-tip::after {
animation: hfx-tooltip-typewriter-blink 0.9s steps(1) 1s infinite;
}
@keyframes hfx-tooltip-typewriter-type {
from { width: 0; }
to { width: 11ch; }
}
@keyframes hfx-tooltip-typewriter-blink {
50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.hfx-tooltip-typewriter, .hfx-tooltip-typewriter *, .hfx-tooltip-typewriter::before, .hfx-tooltip-typewriter::after, .hfx-tooltip-typewriter *::before, .hfx-tooltip-typewriter *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-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.