A quiet dot on the bell grows into an unread count with a springy pop while the clapper swings. The dot and the count are one element: the number only turns visible as it scales up.
Also known as: notification bell badge animation, badge pop css, unread count icon.
<button class="hfx-bell-icon-badge" aria-label="Notifications, 3 unread"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path class="hfx-bell-icon-badge-clapper" d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg> <span class="hfx-bell-icon-badge-count" aria-hidden="true">3</span> </button>
.hfx-bell-icon-badge {
--c: var(--hfx-color, #3b82f6);
font-size: var(--hfx-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 3.5em;
height: 3.5em;
padding: 0;
border: 0;
border-radius: 50%;
cursor: pointer;
background: color-mix(in srgb, var(--c) 12%, transparent);
color: var(--c);
transition: background-color 0.25s ease;}
.hfx-bell-icon-badge svg {
width: 1.55em;
height: 1.55em;
overflow: visible;
}
.hfx-bell-icon-badge-clapper {
transform-box: view-box;
}
.hfx-bell-icon-badge-count {
position: absolute;
top: 0.35em;
right: 0.3em;
display: grid;
place-items: center;
min-width: 1.7em;
height: 1.7em;
padding: 0 0.35em;
border-radius: 1em;
background: var(--c);
color: transparent;
font: 700 0.7em/1 system-ui, sans-serif;
transform: scale(0.42);
transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1), color 0.15s ease;
}
.hfx-bell-icon-badge:is(:hover, :focus-visible) { background: color-mix(in srgb, var(--c) 20%, transparent); }
.hfx-bell-icon-badge:is(:hover, :focus-visible) .hfx-bell-icon-badge-count {
color: #fff;
transform: translate(0.35em, -0.45em) scale(1);
transition-delay: 0s, 0.12s;
}
.hfx-bell-icon-badge:is(:hover, :focus-visible) .hfx-bell-icon-badge-clapper {
animation: hfx-bell-icon-badge-swing 0.8s ease-in-out;
}
@keyframes hfx-bell-icon-badge-swing {
0%, 100% { transform: translateX(0); }
20% { transform: translateX(9%); }
45% { transform: translateX(-7%); }
70% { transform: translateX(3%); }
}
@media (prefers-reduced-motion: reduce) {
.hfx-bell-icon-badge, .hfx-bell-icon-badge *, .hfx-bell-icon-badge::before, .hfx-bell-icon-badge::after, .hfx-bell-icon-badge *::before, .hfx-bell-icon-badge *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--hfx-color on the element or a parent.
Currently previewing #3b82f6.--hfx-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.