07キーボードフォーカスで表示
マウスホバーだけでなく Tab キーでフォーカスを移しても同じツールチップが出る。
使いどころキーボードのみで操作するユーザー向けのフォームラベル説明、アクセシブルなアイコンボタン
:focus-visible:hover 동시 대응aria-describedby

<main class="stage">
<div class="tip-wrap">
<button class="gear-btn" type="button" aria-describedby="tip07">設定</button>
<span class="tooltip is-demo" role="tooltip" id="tip07">Tabキーで移動しても表示されます</span>
</div>
</main>@use "../../../../site/static/demo-tokens" as *;
$duration: $dur-loop; // 숨김→표시→숨김 한 주기
$easing: $ease-out;
$color: $subject-cream; // 버튼·툴팁 색 (주황 무대라 크림)
@include stage($stage-orange);
.tip-wrap { position: relative; }
.gear-btn {
border: 2px solid $color;
border-radius: $r-control;
padding: 10px 24px;
font-weight: 600;
font-size: 15px;
line-height: 1;
font-family: inherit;
color: $subject-ink; // AA: 주황 무대 위 글자 5.50:1 (테두리는 크림 유지)
background: transparent;
cursor: pointer;
}
.tooltip {
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
transform-origin: bottom center; // 규칙8: 버튼 쪽 아래변 축 — 흔들림의 회전 중심
transform: translateX(-50%) scale(.85);
opacity: 0;
background: $color;
color: $stage-orange;
padding: 8px 14px;
border-radius: $r-control;
font-size: clamp(12px, 3.4vw, 14px);
white-space: nowrap;
pointer-events: none;
}
// 실사용: 마우스 호버뿐 아니라 :focus-visible 에도 같은 규칙이 붙는다 (버튼을 Tab 으로 옮겨도 뜬다)
.gear-btn:hover + .tooltip,
.gear-btn:focus-visible + .tooltip {
opacity: 1;
}
// 데모: 실제 포커스 없이 혼자 표시→숨김을 반복한다
// 등장에 스프링 한 겹 — 스케일 .85 → 1.12 오버슛 → 감쇠 반동, 회전은 아래변 축으로 2.6° → -1.5° → .6° 감쇠
.tooltip.is-demo {
animation: tip-loop $duration $easing infinite;
}
@keyframes tip-loop {
0% { opacity: 0; transform: translateX(-50%) scale(.85) rotate(0deg); }
12% { opacity: 1; transform: translateX(-50%) scale(1.12) rotate(2.6deg); }
22% { opacity: 1; transform: translateX(-50%) scale(.95) rotate(-1.5deg); }
30% { opacity: 1; transform: translateX(-50%) scale(1.03) rotate(.6deg); }
36%, 55% { opacity: 1; transform: translateX(-50%) scale(1) rotate(0deg); }
80% { opacity: 0; transform: translateX(-50%) scale(.85) rotate(0deg); }
100% { opacity: 0; transform: translateX(-50%) scale(.85) rotate(0deg); }
}
@media (prefers-reduced-motion: reduce) {
.tooltip.is-demo { animation: none; opacity: 1; transform: translateX(-50%) scale(1) rotate(0deg); }
}html, body {
margin: 0;
overflow: hidden;
}
.stage {
box-sizing: border-box;
min-height: 100vh;
display: grid;
place-items: center;
margin: 0;
background: #ff4d1f;
font-family: -apple-system, "Segoe UI", "Noto Sans KR", sans-serif;
padding: clamp(8px, 4vw, 24px);
}
.tip-wrap {
position: relative;
}
.gear-btn {
border: 2px solid #fff7e6;
border-radius: 12px;
padding: 10px 24px;
font-weight: 600;
font-size: 15px;
line-height: 1;
font-family: inherit;
color: #17141a;
background: transparent;
cursor: pointer;
}
.tooltip {
position: absolute;
bottom: calc(100% + 8px);
left: 50%;
transform-origin: bottom center;
transform: translateX(-50%) scale(0.85);
opacity: 0;
background: #fff7e6;
color: #ff4d1f;
padding: 8px 14px;
border-radius: 12px;
font-size: clamp(12px, 3.4vw, 14px);
white-space: nowrap;
pointer-events: none;
}
.gear-btn:hover + .tooltip,
.gear-btn:focus-visible + .tooltip {
opacity: 1;
}
.tooltip.is-demo {
animation: tip-loop 2s ease-out infinite;
}
@keyframes tip-loop {
0% {
opacity: 0;
transform: translateX(-50%) scale(0.85) rotate(0deg);
}
12% {
opacity: 1;
transform: translateX(-50%) scale(1.12) rotate(2.6deg);
}
22% {
opacity: 1;
transform: translateX(-50%) scale(0.95) rotate(-1.5deg);
}
30% {
opacity: 1;
transform: translateX(-50%) scale(1.03) rotate(0.6deg);
}
36%, 55% {
opacity: 1;
transform: translateX(-50%) scale(1) rotate(0deg);
}
80% {
opacity: 0;
transform: translateX(-50%) scale(0.85) rotate(0deg);
}
100% {
opacity: 0;
transform: translateX(-50%) scale(0.85) rotate(0deg);
}
}
@media (prefers-reduced-motion: reduce) {
.tooltip.is-demo {
animation: none;
opacity: 1;
transform: translateX(-50%) scale(1) rotate(0deg);
}
}import type { CSSProperties, ReactNode } from "react";
import styles from "./FocusTooltip.module.scss";
export type FocusTooltipProps = {
label: ReactNode;
text: string;
duration?: number;
easing?: string;
color?: string;
};
type Vars = CSSProperties & { "--duration"?: string; "--easing"?: string; "--color"?: string };
// :hover 와 :focus-visible 을 CSS 에서 같이 걸어 뒀다 — Tab 으로 옮겨도 마우스 호버와 같은 툴팁이 뜬다.
export default function FocusTooltip({
label,
text,
duration = 200,
easing = "ease-out",
color = "#fff7e6",
}: FocusTooltipProps) {
const vars: Vars = { "--duration": `${duration}ms`, "--easing": easing, "--color": color };
return (
<span className={styles.wrap} style={vars}>
<button type="button" className={styles.btn} aria-describedby="focus-tooltip">
{label}
</button>
<span id="focus-tooltip" role="tooltip" className={styles.tooltip}>
{text}
</span>
</span>
);
}07 キーボードフォーカスで表示 — 計測 累積面積 5.953% · 動いたフレーム 14/23GODRICH オリジナル · SCSS と React は zip に同梱 · CSS ツールチップ 吹き出しアニメーション9選 一行でコピペOK
このデモが属する記事
CSS ツールチップ 吹き出しアニメーション9選 一行でコピペOKcss ツールチップ 吹き出しは、ボタンやアイコンにカーソルを合わせると短い説明が浮かび上がる小さな部品です。今回は9種類を選び、位置合わせの基本からCSS Anchor PositioningやPopover APIといった新しい仕組みま この記事のデモをすべて見る


