Skip to content
IndexRequest a UIAboutContact

Notification Bell with Badge

A bell icon that rings and pops a count badge when something new arrives.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a bell icon button 44px wide with a 20px red circular badge on its top right showing an unread count, plus a "Simulate notification" text button. When a notification arrives, increment the count (cap the display at "9+"), play a bell swing animation by rotating the bell icon around its top centre through -14, 12, -8, 5 and 0 degrees over 700ms ease-in-out, and pop the badge with a scale 0 to 1.2 to 1 over 260ms. Update the button's aria-label to "Notifications, N unread" and announce "New notification" in a polite live region. Clicking the bell clears the count, removes the badge and sets the label to "Notifications". Retrigger the animation reliably by removing and re-adding the class. Show a 2px focus-visible ring. Under prefers-reduced-motion remove the swing and use a 150ms badge fade.

About this pattern

Definition

An icon button with a small number badge. When a new notification arrives the bell swings briefly and the badge pops to the new count; opening it clears the badge.

Purpose & UX principles

  • Draws attention to new activity once, without looping animations.
  • The badge number is part of the button's accessible name ("Notifications, 3 unread").
  • The ring is short and happens only on arrival, so it does not become noise.

Interaction states

  • No unread (no badge), unread (badge), ringing, open (badge cleared), focus-visible.

Motion specification

  • Bell swing: rotate -14, 12, -8, 5, 0 degrees over 700ms ease-in-out, pivoting at the top centre.
  • Badge pop: scale 0 to 1.2 to 1 in 260ms.
  • Reduced motion: no swing; the badge appears with a 150ms fade.

Responsive behaviour

  • 44px button; the badge scales with the icon and caps at "9+".

Code

HTML
<div class="wrap">
  <button class="bell" id="bell" aria-label="Notifications"><svg viewBox="0 0 24 24" width="24" height="24" aria-hidden="true"><path d="M6 17V11a6 6 0 0 1 12 0v6l1.500 2h-15zM10 21h4"/></svg><b class="bd" id="bd" hidden>0</b></button>
  <button class="sim" id="sim" type="button">Simulate notification</button>
  <p class="live" id="live" aria-live="polite"></p>
</div>

Related patterns

Icon Button

↗
Icon ButtonButtons & Actions

Toast

↗
ToastFeedback & Notifications

Snackbar

↗
SnackbarFeedback & Notifications