툴팁

Tooltip

마우스를 올리거나 키보드로 포커스했을 때 나타나는, 클릭할 수 없는 짧은 보조 설명.

다른 이름: HintTitle tip
···
html
<div class="wrap">
  <button class="icon-btn" id="ib" aria-describedby="tp">💾</button>
  <span class="tip" id="tp" role="tooltip">저장</span>
  <i class="cursor" id="cur"></i>
</div>
css
.wrap{position:relative;display:grid;place-items:center;width:100%;height:100%}
.icon-btn{width:46px;height:46px;border-radius:12px;border:1px solid var(--line);background:var(--surface);font-size:18px;cursor:pointer}
.tip{position:absolute;left:50%;bottom:calc(50% + 34px);transform:translate(-50%,4px);background:var(--fg);color:var(--bg);
  font-size:11px;font-weight:600;padding:5px 9px;border-radius:6px;white-space:nowrap;opacity:0;pointer-events:none;transition:opacity .16s,transform .16s}
.tip[data-show]{opacity:1;transform:translate(-50%,0)}
.cursor{position:absolute;width:12px;height:12px;border-radius:50%;background:var(--accent);opacity:.85;
  top:calc(50% + 40px);left:calc(50% + 40px);box-shadow:0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  transition:top .5s ease,left .5s ease}
js
const btn = document.getElementById('ib'), tip = document.getElementById('tp'), cur = document.getElementById('cur');
function showReal() { tip.setAttribute('data-show', ''); }
function hideReal() { tip.removeAttribute('data-show'); }
btn.addEventListener('mouseenter', showReal);
btn.addEventListener('mouseleave', hideReal);
btn.addEventListener('focus', showReal);
btn.addEventListener('blur', hideReal);
let auto = true;
btn.addEventListener('pointerdown', () => auto = false);
function loop() {
  if (!auto) return;
  cur.style.top = '50%'; cur.style.left = '50%'; cur.style.transform = 'translate(-50%,-50%)';
  setTimeout(() => { if (auto) showReal(); }, 520);
  setTimeout(() => {
    if (!auto) return; hideReal();
    cur.style.top = 'calc(50% + 40px)'; cur.style.left = 'calc(50% + 40px)'; cur.style.transform = 'none';
    setTimeout(loop, 900);
  }, 1900);
}
loop();

아이콘 버튼처럼 라벨이 없는 요소의 의미를 보충하는 순수 텍스트입니다. role="tooltip"을 주고 트리거 요소에 aria-describedby로 연결합니다. 마우스가 벗어나거나 포커스가 빠지면 즉시 사라져야 합니다.

팝오버와 가장 많이 헷갈립니다. 툴팁은 텍스트만 담고 안에 아무것도 클릭할 수 없으며 hover/focus로 열립니다. 팝오버는 버튼·링크·폼 같은 상호작용 가능한 콘텐츠를 담을 수 있고 보통 클릭으로 열어서 바깥을 클릭해야 닫힙니다 — 툴팁 안에 "자세히 보기" 버튼을 넣고 싶어지면 그건 이미 팝오버입니다.

마우스만으로 hover에 의존하면 키보드·터치 사용자는 절대 못 봅니다. 트리거는 반드시 포커스 가능한 요소여야 하고, focus 이벤트에서도 같은 툴팁이 떠야 합니다.