176 web animation techniques, each a live demo with plain settings and a ready-made prompt for your AI assistant. No dependencies, no build step.
HTML ai-promptsanimationcss-animationsfrontendgithub-pagesjavascriptmicrointeractionsmotion-designno-dependenciesreferencescroll-animationui-animationweb-animationweb-developmentwebgl
fix: keep Notification Badge Pulse's number readable and its labels true
matinc69239418704
diff --git a/animations/04-micro-interactions/badge-pulse/README.md b/animations/04-micro-interactions/badge-pulse/README.mdindex c8b9fe0a..581e3639 100644--- a/animations/04-micro-interactions/badge-pulse/README.md+++ b/animations/04-micro-interactions/badge-pulse/README.md@@ -35,13 +35,18 @@ The badge pulses via a looping `scale` keyframe animation:}```-The halo variant adds a radiating ring that expands and fades:+The halo variant adds a radiating ring that expands and fades. The ring is drawn under the badge's number, not over it: the badge is its own stacking context (`isolation: isolate`) and the ring has a negative `z-index`, so it covers the badge's color but never the number, which keeps its contrast through every pulse:```css+.badge {+ isolation: isolate;+}+.badge::after {content: '';position: absolute;inset: -4px;+ z-index: -1;border-radius: 50%;background: var(--badge-color);opacity: 0.4;@@ -54,6 +59,8 @@ The halo variant adds a radiating ring that expands and fades:}```+Stopping after three pulses takes two more declarations on the animated parts, `animation-iteration-count: 3` and `animation-fill-mode: forwards`. Without the fill mode the badge would fall back to the halo's resting style, a faint ring, when the last pulse ends; with it the run stays on its last keyframes, the badge at scale 1 and the halo invisible.+## Key parameters| Parameter | Default | Effect ||-----------|---------|--------|diff --git a/animations/04-micro-interactions/badge-pulse/index.html b/animations/04-micro-interactions/badge-pulse/index.htmlindex 0ca993a4..df30830a 100644--- a/animations/04-micro-interactions/badge-pulse/index.html+++ b/animations/04-micro-interactions/badge-pulse/index.html@@ -31,8 +31,9 @@.icon-round{border-radius:50%}@media(hover:hover){.icon-btn:hover{border-color:var(--ui-accent)}}.icon-label{font-size:11px;color:var(--ui-muted);text-align:center}- /* Badge: the number is dark because white on these colors is below 4.5:1 */- .badge{position:absolute;top:-8px;right:-8px;min-width:22px;height:22px;border-radius:11px;background:var(--badge-color);color:#0b0b0d;font-size:11px;font-weight:bold;display:flex;align-items:center;justify-content:center;padding:0 5px;border:2px solid var(--bg)}+ /* Badge: the number is dark because white on these colors is below 4.5:1. The badge is a stacking context of its own, so the halo+ below (z-index -1) is drawn over its color but under the number, and the number keeps its contrast through every pulse. */+ .badge{position:absolute;top:-8px;right:-8px;min-width:22px;height:22px;border-radius:11px;background:var(--badge-color);color:#0b0b0d;font-size:11px;font-weight:bold;display:flex;align-items:center;justify-content:center;padding:0 5px;border:2px solid var(--bg);isolation:isolate}/* Dot badge */.dot-badge{position:absolute;top:-4px;right:-4px;width:14px;height:14px;border-radius:50%;background:var(--badge-color);border:2px solid var(--bg)}/* Pulse scale only */@@ -44,8 +45,9 @@/* Both */.pulse-both .badge,.pulse-both .dot-badge{animation:badge-scale var(--pulse-dur) ease-in-out infinite}.pulse-both .badge::after,.pulse-both .dot-badge::after{content:'';position:absolute;inset:-4px;border-radius:50%;background:var(--badge-color);opacity:.4;animation:halo-grow var(--pulse-dur) ease-out infinite}- /* Stops after three pulses */- .fade-mode .badge,.fade-mode .dot-badge,.fade-mode .badge::after,.fade-mode .dot-badge::after{animation-iteration-count:3!important}+ .badge::after{z-index:-1}+ /* Stops after three pulses: the last pulse ends on its last keyframes (badge at scale 1, halo invisible) and stays there */+ .fade-mode .badge,.fade-mode .dot-badge,.fade-mode .badge::after,.fade-mode .dot-badge::after{animation-iteration-count:3!important;animation-fill-mode:forwards!important}/* Status dot (online) */.status-dot{position:absolute;bottom:-2px;right:-2px;width:16px;height:16px;border-radius:50%;background:#56d364;border:2px solid var(--bg);animation:badge-scale var(--pulse-dur) ease-in-out infinite}</style>@@ -198,6 +200,8 @@const stage=document.querySelector('.stage');const vars=document.documentElement.style;const icons=[...document.querySelectorAll('.icon-btn')];+ // While its badge shows, an icon's label says what the badge says ("Notifications, 3 new"); the part before the comma names the icon alone+ const fullLabel=new Map(icons.map(ic=>[ic,ic.getAttribute('aria-label')]));let currentStyle='pulse-scale',pulseMs=1500;// Taking the pulse class off, reading the layout and putting it back starts the bell's and the inbox's animations again@@ -211,17 +215,20 @@});}- // Clicking an icon, or pressing Enter or Space on it, clears its badge; Reset shows every badge again at once.+ // Clicking an icon, or pressing Enter or Space on it, clears its badge and its label stops announcing it; Reset brings both back at once.icons.forEach(ic=>{const dismiss=()=>{const b=ic.querySelector('.badge,.dot-badge');- if(b)b.style.display='none';+ if(!b)return;+ b.style.display='none';+ ic.setAttribute('aria-label',fullLabel.get(ic).split(',')[0]);};ic.addEventListener('click',dismiss);ic.addEventListener('keydown',e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();dismiss()}});});document.getElementById('btn-reset').addEventListener('click',()=>{document.querySelectorAll('.badge,.dot-badge').forEach(b=>{b.style.display=''});+ icons.forEach(ic=>ic.setAttribute('aria-label',fullLabel.get(ic)));applyStyle();});@@ -232,14 +239,20 @@pick(b.dataset);}));}- choices('style-seg',d=>{currentStyle=d.style;applyStyle()});- // A new --pulse-dur keeps the time already played, so every pulse would jump to another point of its cycle.- // Scaling each animation's time by the same factor as its length keeps the pulses where they are, moving or paused.+ // Pressing the style that is already chosen changes nothing; it must not restart the pulses+ choices('style-seg',d=>{if(d.style===currentStyle)return;currentStyle=d.style;applyStyle()});+ // A new --pulse-dur keeps the time already played, so every pulse would jump to another point of its cycle. Scaling each+ // animation's time by the same factor as its length keeps the pulses where they are: moving, paused or finished (the fill mode of+ // "Stops after three pulses" keeps a finished pulse in the list). The times are read first, the new length goes in and is flushed,+ // and then every pulse is moved.choices('speed-seg',d=>{const next=+d.ms;- stage.getAnimations({subtree:true}).forEach(a=>{if(a.animationName&&a.currentTime!=null)a.currentTime=a.currentTime*next/pulseMs});- pulseMs=next;+ if(next===pulseMs)return;+ const pulses=stage.getAnimations({subtree:true}).filter(a=>a.animationName).map(a=>[a,a.currentTime]);vars.setProperty('--pulse-dur',next+'ms');+ void stage.offsetWidth;+ pulses.forEach(([a,t])=>{if(t!=null)a.currentTime=t*next/pulseMs});+ pulseMs=next;});choices('grow-seg',d=>{vars.setProperty('--pulse-scale',d.scale)});choices('color-sw',d=>{vars.setProperty('--badge-color',d.c)});diff --git a/docs/superpowers/plans/2026-09-29-micro-content-part1.md b/docs/superpowers/plans/2026-09-29-micro-content-part1.mdindex c06d6b5f..329440cd 100644--- a/docs/superpowers/plans/2026-09-29-micro-content-part1.md+++ b/docs/superpowers/plans/2026-09-29-micro-content-part1.md@@ -1067,29 +1067,30 @@ How far it rises and Size when raised move the underlined fields' labels; the bo- **Description:** A badge on an icon pulses to catch the eye. Best for unread messages.- **Watch it help line:** "It moves by itself. Pause it, or click an icon to clear its badge; Reset brings the badges back."- **Player bar:** Pause (css) · Reset · Slow motion (css). Reset is the do-it plan's Reset button (`id="btn-reset"`, `data-hb-reset`) and sits between Pause and Slow motion; on phones Pause and Reset share a row.-- **Sequence:** the bell's and the inbox's badges pulse forever in the chosen Pulse style (`badge-scale`, `halo-grow` or both, over Speed). The avatar's online dot always grows and shrinks (`badge-scale`). No page timers. Clicking the bell or the inbox, or pressing Enter or Space on it, clears its badge (`display:none`), as today.-- **Reset:** shows every cleared badge again and restarts the pulses with `applyStyle()`. While paused, the restarted pulses wait at their first frame (the shared `hb-paused` class holds them) until Play.+- **Sequence:** the bell's and the inbox's badges pulse forever in the chosen Pulse style (`badge-scale`, `halo-grow` or both, over Speed). The avatar's online dot always grows and shrinks (`badge-scale`). No page timers. Clicking the bell or the inbox, or pressing Enter or Space on it, clears its badge (`display:none`), as today, and the icon's `aria-label` loses the count so that screen readers no longer announce a badge that is gone: "Notifications, 3 new" becomes "Notifications" and "Inbox, new messages" becomes "Inbox" (the full labels are kept for Reset; "Profile, online" never changes).+- **Reset:** shows every cleared badge again, restores the full labels and restarts the pulses with `applyStyle()`. While paused, the restarted pulses wait at their first frame (the shared `hb-paused` class holds them) until Play.- **Slow motion:** css- **Reduced motion:** the demo's rule goes (it removed the pulses and hid the halos, and Play must move them).-- **Stage font:** site font. `.icon-label` becomes 11px, keeping its `--ui-muted` grey; the number in the badge becomes 11px.-- **Stage:** the three icons stay. Their two-line labels become one word each: "Number", "Dot" and "Online" (were "Bell numbered", "Inbox dot" and "Avatar online"). The avatar's inline style moves into a class. `hb-dots`: yes. Measured: 168px of content, centred.+- **Stage font:** site font. `.icon-label` becomes 11px, keeping its `--ui-muted` grey; the number in the badge becomes 11px and dark (`#0b0b0d`), not white: white on the five badge colors is 3.35 to 1.94:1 and the dark number 5.87 to 10.15:1 (text needs 4.5:1).+- **Stage:** the three icons stay. Their two-line labels become one word each: "Number", "Dot" and "Online" (were "Bell numbered", "Inbox dot" and "Avatar online"). The avatar's inline style moves into a class. `hb-dots`: yes. Measured: 90px of content (the badges stick out 8px above it), centred; it fits every stage, the 260px one included.+- **Halo layering:** the halo (`::after`) is drawn over the badge's color and under its number: `.badge{isolation:isolate}` makes the badge a stacking context and `.badge::after{z-index:-1}` puts the halo inside it, below the text. A halo painted over the number took it below 4.5:1 (2.66:1 on Red at the start of every Ring or Both pulse, 3.27 to 4.15:1 at rest); with the halo under it the number measures 5.86:1 or better in every state.**Main settings**| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo ||---|---|---|---|---|---|-| Pulse style | Choice buttons | Grow · Ring · Both | Grow | Grow stays contained; Ring spreads a soft halo. | the bell's and the inbox's class: `pulse-scale` / `pulse-halo` / `pulse-both`, then `applyStyle()` |-| Speed | Choice buttons | Slow · Normal · Fast | Normal | Fast feels urgent; slow is easy to miss. | `--pulse-dur`: 2.4s / 1.5s / 0.9s |+| Pulse style | Choice buttons | Grow · Ring · Both | Grow | Grow stays contained; Ring spreads a soft halo. | the bell's and the inbox's class: `pulse-scale` / `pulse-halo` / `pulse-both`, then `applyStyle()`; pressing the style already chosen does nothing (it must not restart the pulses) |+| Speed | Choice buttons | Slow · Normal · Fast | Normal | Fast feels urgent; slow is easy to miss. | `--pulse-dur`: 2.4s / 1.5s / 0.9s; every pulse is moved to the same point of its new length, so the picture stays (moving, paused or finished) || How much it grows | Choice buttons | Slightly · Medium · A lot | Medium | Much bigger than a third starts to feel alarming. | `--pulse-scale`: 1.15 / 1.3 / 1.5 |**More options**| Setting | Control | Choices or range (value shown) | Default | Hint | Sets in the demo ||---|---|---|---|---|---|-| Stops after three pulses | Switch | on / off | off | Pulses three times to be noticed, then rests. | every icon's `fade-mode` class on / off, then `applyStyle()`, as today |+| Stops after three pulses | Switch | on / off | off | Pulses three times to be noticed, then rests. | every icon's `fade-mode` class on / off, then `applyStyle()`; the rule sets `animation-iteration-count:3` and `animation-fill-mode:forwards`, so the run ends on its last keyframes (badge at scale 1, halo invisible) and a finished pulse stays in `getAnimations()` for Speed || Badge color | Swatches (Red, the default, added; White and Green left out) | Red · Pink · Blue · Purple · Orange | Red | Red reads as new and urgent. | `--badge-color`: `#f85149` / `#ff6f8b` / `#58a6ff` / `#d2a8ff` / `#ffa657` |-White is left out because the badge's number is white, and Green because the online dot is green. How much it grows also sets the online dot's pulse, whatever the Pulse style.+White stays left out (it was left out when the number was white; the number is dark now, so White could be added if the owner wants it), and Green because the online dot is green. How much it grows also sets the online dot's pulse, whatever the Pulse style.- **Removed:**- The note and the "Click an icon to dismiss its badge." line; the help line says it.@@ -1121,7 +1122,7 @@ White is left out because the badge's number is white, and Green because the onl- [Tooltip Reveal](../tooltip-reveal/) — pointing at an icon shows a short note- [Loading Spinner](../loading-spinner/) — another sign that something is going on- [Hover State Animation](../hover-state/) — items react when the pointer is over them-- **README How it works:** unchanged+- **README How it works:** the halo snippet gains `.badge{isolation:isolate}` and `z-index:-1` on `.badge::after`, with a sentence saying the ring is drawn under the number, and a sentence after it says the three-pulse run uses `animation-iteration-count:3` and `animation-fill-mode:forwards`. The rest is unchanged.- **README Production notes:** the `prefers-reduced-motion` bullet becomes: "**`prefers-reduced-motion`**: under reduced motion the demo starts paused, so the badges stay still until the visitor presses Play. In production, turn the pulse off: the badge stays visible, just without motion." The rest is unchanged.- **Category line:** `04.15 · Micro-Interactions`- **Pager:** Previous: Form Field Morph (`../form-field-morph/`) · Next: Tooltip Reveal (`../tooltip-reveal/`)