알림 배지Notification badge
종 아이콘 모서리에 읽지 않은 알림 수를 빨간 동그라미로 보여 줘요. 숫자가 바뀔 때 살짝 튀어서 새 소식이 왔다는 걸 눈치채게 해요.
이럴 때 써요
- 읽지 않은 알림·메시지 수를 알릴 때
- 장바구니에 담긴 개수처럼 계속 바뀌는 숫자를 보여 줄 때
- 새 기능 메뉴에 점 하나로 "새것" 표시를 할 때
이럴 땐 다른 걸 써요
- 내용까지 알려야 하면 → 토스트나 인라인 알림
- 수가 늘 많아서 의미가 없으면 → 배지 대신 점 하나만
무엇으로 이루어지나
- 기준 아이콘 단추
- 빨간 동그라미(바탕색 테두리 2px 로 아이콘과 분리)
- 숫자(99를 넘으면 "99+")
- 화면 읽기용 이름("알림 3개")
잘 만드는 요령
- 배지 둘레에 바탕색 테두리를 2px 두르면 아이콘 위에 겹쳐도 또렷하게 떨어져 보여요.
- 숫자가 늘 때만 짧게(300ms) 튀게 하고, 0 이 되면 작아지며 사라지게 해요. 계속 깜빡이는 배지는 불안을 만들어요.
- 배지 숫자는 그림일 뿐이라, 단추 이름(aria-label)에 "알림 3개"처럼 수를 넣어야 화면 읽기 프로그램이 읽어요.
- 두 자리부터는 동그라미가 옆으로 늘어나게(min-width + 좌우 여백) 만들어야 숫자가 잘리지 않아요.
AI 에게 시키는 프롬프트
Claude·ChatGPT 에 붙여 넣으면 위 데모와 비슷한 화면을 HTML 파일 하나로 만들어 줘요. 글자·색은 바꿔 쓰세요.
흰 동그란 종 아이콘 단추 오른쪽 위에 빨간 알림 배지를 만들어 줘. 배지는 높이 18px, 최소 너비 18px 알약 모양이고 바탕색 2px 테두리로 아이콘과 떨어져 보여. 99를 넘으면 "99+". 옆에 "알림 하나 더", "한꺼번에 50개", "모두 읽음" 단추를 두고, 수가 늘면 배지가 scale .6→1 로 300ms 튀어 오르고(cubic-bezier(.34,1.56,.64,1)) 종이 좌우로 살짝 흔들려. 0 이 되면 배지가 작아지며 사라져. 종 단추의 aria-label 은 "알림 N개"로 바뀌고, 새 알림이 오면 화면에 안 보이는 aria-live 문장으로도 알려 줘. 조건: 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}}
/* 알림 배지 */
.row{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:20px}
.actions{display:flex;flex-wrap:wrap;justify-content:center;gap:8px}
.bell{position:relative;display:grid;place-items:center;width:48px;height:48px;border:0;border-radius:999px;background:var(--surface);box-shadow:var(--shadow-surface);cursor:pointer}
.bell svg{transform-origin:50% 15%}
.bell.ring svg{animation:ring .5s ease-in-out}
.badge{position:absolute;top:2px;right:0;min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:var(--danger);color:#fff;
font-size:11px;font-weight:700;line-height:18px;text-align:center;box-shadow:0 0 0 2px var(--bg);transition:transform .15s ease-out,opacity .15s ease-out}
.badge.pop{animation:pop .3s cubic-bezier(.34,1.56,.64,1)}
.badge.zero{transform:scale(0);opacity:0}
@keyframes pop{from{transform:scale(.6)}to{transform:scale(1)}}
@keyframes ring{0%,100%{transform:rotate(0)}25%{transform:rotate(14deg)}50%{transform:rotate(-10deg)}75%{transform:rotate(5deg)}}
</style>
</head>
<body>
<div class="row">
<button class="bell" id="bell" aria-label="알림 3개"><svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 16v-5a6 6 0 0 1 12 0v5l1.5 2h-15z"/><path d="M10 20.5a2 2 0 0 0 4 0"/></svg><span class="badge" id="badge" aria-hidden="true">3</span></button>
<div class="actions">
<button class="btn" id="one">알림 하나 더</button>
<button class="btn" id="many">한꺼번에 50개</button>
<button class="btn" id="read">모두 읽음</button>
</div>
</div>
<p class="sr" id="live" aria-live="polite"></p>
<script>
const bell = document.getElementById('bell');
const badge = document.getElementById('badge');
const live = document.getElementById('live');
let count = 3;
function restart(element, name) {
element.classList.remove(name);
void element.offsetWidth;
element.classList.add(name);
}
function render(added) {
badge.textContent = count > 99 ? '99+' : String(count);
badge.classList.toggle('zero', count === 0);
bell.setAttribute('aria-label', count === 0 ? '새 알림 없음' : '알림 ' + count + '개');
if (added) {
restart(badge, 'pop');
restart(bell, 'ring');
live.textContent = '새 알림 ' + added + '개가 왔어요';
}
}
document.getElementById('one').addEventListener('click', function () { count += 1; render(1); });
document.getElementById('many').addEventListener('click', function () { count += 50; render(50); });
document.getElementById('read').addEventListener('click', function () { count = 0; render(0); live.textContent = '알림을 모두 읽었어요'; });
</script>
</body>
</html>