툴팁Tooltip
아이콘 단추에 마우스를 올리거나 키보드로 고르면 이름과 단축키를 작게 보여 주는 말풍선이에요. 글자 없는 단추가 무슨 일을 하는지 알려 줘요.
이럴 때 써요
- 글자 없이 아이콘만 있는 단추의 이름을 알려 줄 때
- 단축키를 함께 알려 주고 싶을 때
- 줄인 글자나 숫자의 전체 값을 보여 줄 때
이럴 땐 다른 걸 써요
- 폰(터치)에서 꼭 봐야 하는 설명 → 화면에 글자로 적기(툴팁은 손가락으로 못 띄워요)
- 단추나 링크가 들어간 내용 → 팝오버
- 오류 안내 → 인라인 알림
무엇으로 이루어지나
- 기준 단추
- 작은 말풍선(단추 위, 8px 띄움)
- 이름 한 단어
- 단축키 표시(선택)
잘 만드는 요령
- 마우스를 올리고 0.4초쯤 기다렸다 띄워요. 화면을 지나가기만 해도 툴팁이 번쩍이면 산만해요.
- 하나가 떠 있는 상태에서 옆 단추로 옮기면 기다리지 않고 바로 바꿔 보여 줘요. 툴바를 훑어볼 때 훨씬 빨라요.
- 키보드 포커스로도 떠야 하고 Esc 로 닫혀야 해요. 아이콘 단추의 이름은 툴팁 글자를 aria-labelledby 로 연결해요.
- 나타날 때 150ms 동안 90% 크기에서 커지고, 사라질 때는 100ms 로 빨리 사라지게 해요.
AI 에게 시키는 프롬프트
Claude·ChatGPT 에 붙여 넣으면 위 데모와 비슷한 화면을 HTML 파일 하나로 만들어 줘요. 글자·색은 바꿔 쓰세요.
글자 꾸미기 툴바(굵게·기울임·밑줄 아이콘 단추 3개)와 그 아래 예시 문장을 만들어 줘. 각 단추에 마우스를 올리면 0.4초 뒤 단추 위 8px 에 툴팁이 떠서 "굵게 ⌘B" 처럼 이름과 단축키를 보여 줘. 툴팁이 떠 있을 때 옆 단추로 옮기면 기다리지 않고 바로 바꿔 보여 주고, 마우스가 툴바를 떠난 뒤 0.3초가 지나면 다시 기다리기 상태로 돌아가. 키보드 포커스로도 바로 뜨고 Esc 로 닫혀. 툴팁은 흰 말풍선(모서리 10px, 떠 있는 그림자)이고 나타날 때 scale .9→1 150ms, 사라질 때 100ms. 단추를 누르면 aria-pressed 가 바뀌고 예시 문장에 굵게·기울임·밑줄이 적용돼. 조건: HTML 파일 하나에 CSS·자바스크립트를 함께 넣고 외부 라이브러리는 쓰지 마. 움직임은 transform·opacity 만 쓰고, prefers-reduced-motion 이 켜져 있으면 움직임을 끄고 결과만 보여 줘. 밝은 화면과 어두운 화면(prefers-color-scheme) 둘 다 맞추고, 폰 폭 320px 에서도 깨지지 않게. 키보드로도 쓸 수 있게 하고 포커스 링이 보이게 해 줘. 강조색은 파랑(#0485F7), 글꼴은 Pretendard.
HTML 코드
위 데모를 돌리는 코드 그대로예요. 파일 하나로 저장해 브라우저로 열면 바로 움직여요. 자유롭게 고쳐 써도 돼요.
코드 펼쳐 보기
<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>툴팁 — 유틸픽 디자인픽</title>
<style>
/* 바탕 — 밝은 화면 기본, 기기 설정이 어두우면 어두운 화면. <html class="dark"> 나 "light" 로 고정할 수 있어요. */
:root{color-scheme:light;--bg:#f7f7f8;--surface:#ffffff;--surface-2:#f0f0f2;--surface-3:#e6e6ea;--fg:#18181b;--muted:#6b6b76;--border:#e4e4e7;
--accent:#0485f7;--accent-hover:#2b97f8;--accent-fg:#fcfcfc;--accent-soft:rgba(4,133,247,.14);--accent-soft-fg:#1e63ae;
--success:#12a150;--success-soft:rgba(18,161,80,.14);--success-soft-fg:#0e7a3d;
--warning:#e8930c;--warning-soft:rgba(245,165,36,.18);--warning-soft-fg:#8a5300;
--danger:#e5484d;--danger-soft:rgba(229,72,77,.14);--danger-soft-fg:#b4232a;
--shadow-surface:0 2px 4px rgba(0,0,0,.04),0 1px 2px rgba(0,0,0,.06),0 0 1px rgba(0,0,0,.06);
--shadow-float:0 2px 8px rgba(0,0,0,.06),0 -6px 12px rgba(0,0,0,.03),0 14px 28px rgba(0,0,0,.08);
--shine:rgba(255,255,255,.65);
--ease:cubic-bezier(.32,.72,0,1);}
@media (prefers-color-scheme:dark){:root:not(.light){color-scheme:dark;--bg:#0e0e11;--surface:#1b1b20;--surface-2:#25252b;--surface-3:#303037;--fg:#fafafa;--muted:#a1a1aa;--border:#2e2e35;
--accent:#0485f7;--accent-hover:#2b97f8;--accent-fg:#fcfcfc;--accent-soft:rgba(4,133,247,.2);--accent-soft-fg:#61a8fc;
--success:#17c964;--success-soft:rgba(23,201,100,.16);--success-soft-fg:#5fe39a;
--warning:#f5a524;--warning-soft:rgba(245,165,36,.16);--warning-soft-fg:#f7c26b;
--danger:#f2555a;--danger-soft:rgba(242,85,90,.16);--danger-soft-fg:#ff8a8e;
--shadow-surface:inset 0 0 0 1px rgba(255,255,255,.06);
--shadow-float:inset 0 0 0 1px rgba(255,255,255,.12),0 14px 28px rgba(0,0,0,.45);
--shine:rgba(255,255,255,.07);}}
:root.dark{color-scheme:dark;--bg:#0e0e11;--surface:#1b1b20;--surface-2:#25252b;--surface-3:#303037;--fg:#fafafa;--muted:#a1a1aa;--border:#2e2e35;
--accent:#0485f7;--accent-hover:#2b97f8;--accent-fg:#fcfcfc;--accent-soft:rgba(4,133,247,.2);--accent-soft-fg:#61a8fc;
--success:#17c964;--success-soft:rgba(23,201,100,.16);--success-soft-fg:#5fe39a;
--warning:#f5a524;--warning-soft:rgba(245,165,36,.16);--warning-soft-fg:#f7c26b;
--danger:#f2555a;--danger-soft:rgba(242,85,90,.16);--danger-soft-fg:#ff8a8e;
--shadow-surface:inset 0 0 0 1px rgba(255,255,255,.06);
--shadow-float:inset 0 0 0 1px rgba(255,255,255,.12),0 14px 28px rgba(0,0,0,.45);
--shine:rgba(255,255,255,.07);}
*{box-sizing:border-box}
[hidden]{display:none!important}
body{margin:0;min-height:100vh;display:grid;place-items:center;padding:24px;background:var(--bg);color:var(--fg);
font:15px/1.5 Pretendard,-apple-system,BlinkMacSystemFont,system-ui,'Apple SD Gothic Neo',sans-serif;-webkit-font-smoothing:antialiased;word-break:keep-all}
button{font:inherit;color:inherit}
.btn{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:40px;padding:0 16px;border:0;border-radius:999px;
background:var(--surface-2);color:var(--fg);font-size:14px;font-weight:600;cursor:pointer;
transition:transform .25s ease,background-color .1s ease-out}
.btn:active{transform:scale(.97)}
.btn-primary{background:var(--accent);color:var(--accent-fg)}
.btn-danger{background:var(--danger);color:#fff}
@media (hover:hover){.btn:hover{background:var(--surface-3)}.btn-primary:hover{background:var(--accent-hover)}.btn-danger:hover{background:color-mix(in oklab,var(--danger) 90%,#fff)}}
.btn:disabled{opacity:.5;cursor:not-allowed;transform:none}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
@media (prefers-reduced-motion:reduce){*,*::before,*::after{animation-duration:.01ms!important;animation-iteration-count:1!important;transition-duration:.01ms!important}}
/* 툴팁 */
.editor{display:grid;justify-items:center;gap:20px}
.toolbar{display:flex;gap:4px;padding:4px;border-radius:999px;background:var(--surface);box-shadow:var(--shadow-surface)}
.tip-wrap{position:relative}
.tool{display:grid;place-items:center;width:40px;height:40px;border:0;border-radius:999px;background:transparent;font-size:16px;cursor:pointer;transition:background-color .1s ease-out,transform .25s ease}
.tool:active{transform:scale(.94)}
.tool[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent-soft-fg)}
@media (hover:hover){.tool:hover{background:var(--surface-2)}.tool[aria-pressed="true"]:hover{background:var(--accent-soft)}}
.tip{position:absolute;left:50%;bottom:calc(100% + 8px);translate:-50% 0;display:flex;align-items:center;gap:6px;padding:6px 10px;border-radius:10px;
background:var(--surface);box-shadow:var(--shadow-float);font-size:13px;font-weight:600;white-space:nowrap;pointer-events:none;
opacity:0;transform:translateY(4px) scale(.9);transform-origin:bottom center;transition:opacity .1s ease,transform .1s ease}
.tip kbd{padding:1px 5px;border-radius:5px;background:var(--surface-2);color:var(--muted);font:600 11px/1.5 inherit}
.tip-wrap.show .tip{opacity:1;transform:none;transition-duration:.15s}
.sample{margin:0;font-size:18px}
.sample.bold{font-weight:700}.sample.italic{font-style:italic}.sample.underline{text-decoration:underline;text-underline-offset:4px}
</style>
</head>
<body>
<div class="editor">
<div class="toolbar" role="toolbar" aria-label="글자 꾸미기">
<span class="tip-wrap"><button class="tool" aria-labelledby="tip-bold" aria-pressed="false" data-style="bold"><b>B</b></button><span class="tip" role="tooltip" id="tip-bold">굵게 <kbd>⌘B</kbd></span></span>
<span class="tip-wrap"><button class="tool" aria-labelledby="tip-italic" aria-pressed="false" data-style="italic"><i>I</i></button><span class="tip" role="tooltip" id="tip-italic">기울임 <kbd>⌘I</kbd></span></span>
<span class="tip-wrap"><button class="tool" aria-labelledby="tip-underline" aria-pressed="false" data-style="underline"><u>U</u></button><span class="tip" role="tooltip" id="tip-underline">밑줄 <kbd>⌘U</kbd></span></span>
</div>
<p class="sample" id="sample">유틸픽으로 문서를 꾸며 보세요.</p>
</div>
<script>
const wraps = document.querySelectorAll('.tip-wrap');
const sample = document.getElementById('sample');
let warm = false;
let openTimer = 0;
let coolTimer = 0;
function hideAll(except) {
wraps.forEach(function (wrap) { if (wrap !== except) wrap.classList.remove('show'); });
}
function show(wrap) {
clearTimeout(coolTimer);
hideAll(wrap);
wrap.classList.add('show');
warm = true;
}
function hide(wrap) {
clearTimeout(openTimer);
wrap.classList.remove('show');
coolTimer = setTimeout(function () { warm = false; }, 300);
}
wraps.forEach(function (wrap) {
const button = wrap.querySelector('button');
wrap.addEventListener('pointerenter', function () {
clearTimeout(openTimer);
if (warm) show(wrap);
else openTimer = setTimeout(function () { show(wrap); }, 400);
});
wrap.addEventListener('pointerleave', function () { hide(wrap); });
button.addEventListener('focus', function () { if (button.matches(':focus-visible')) show(wrap); });
button.addEventListener('blur', function () { hide(wrap); });
button.addEventListener('click', function () {
const on = button.getAttribute('aria-pressed') !== 'true';
button.setAttribute('aria-pressed', String(on));
sample.classList.toggle(button.dataset.style, on);
});
});
document.addEventListener('keydown', function (event) {
if (event.key === 'Escape') hideAll(null);
});
</script>
</body>
</html>