CSS pulse animation: infinite heartbeat badge without JavaScript

PublishedToolCSS Pulse & Heartbeat Animation Generator

Contents
  1. Why does a notification badge keep beating without JavaScript?
  2. How to check it: build a pulse with keyframes yourself
  3. Common snags
  4. The takeaway
  5. Frequently asked questions

You've probably seen a notification icon or a shopping cart badge grow and shrink like a heartbeat, over and over. It seems like a JavaScript timer must be running nonstop, but it's really just a few lines of CSS. Once you understand how the endless repeat works, you can put the same effect on any icon yourself.

Summary ① The animation repeats forever not because of a JavaScript timer, but because of the CSS value animation-iteration-count: infinite ② The growing and shrinking motion comes from setting scale values at intervals from 0% to 100% inside @keyframes — the browser fills in the frames between them automatically ③ To get the double-beat feel of a real heartbeat, you put two expansion points inside one repeat cycle (one small, one big)

Why does a notification badge keep beating without JavaScript?

It's easy to assume this motion is built with a JavaScript timer like setInterval, but it actually takes just one CSS property: animation. When you define shapes at intervals from 0% to 100% with @keyframes, the browser connects them smoothly on its own.

The key is the value animation-iteration-count. Its default is 1, so the animation plays once and stops. Set it to infinite and the browser automatically starts over from the beginning every time playback finishes. That's why JavaScript doesn't need to handle the repeating.

What's more, scaling done with transform: scale is handled on a graphics layer that's separate from layout calculations. That's also why the badge keeps beating without a stutter even when other scripts on the page are busy.

Repeating alone won't give you a heartbeat feel, though. A real pulse is made of two movements within a single cycle: one small thump, then one bigger one. That rhythm comes not from the repeat setting but from how many intervals you divide the keyframes into.

How to check it: build a pulse with keyframes yourself

The simplest pulse needs just three intervals. Start at 0% at the original size (scale(1)), grow slightly at 50% (scale(1.2)), and return to the original size at 100%.

To apply these keyframes to an element, all you need is the animation property. Write animation: pulse-basic 1.2s ease-in-out infinite; — name, duration, timing function, and iteration count in that order — and there's no need for JavaScript at all in place of infinite.

To get the double-beat feel of a heartbeat, you need two expansion points within one cycle. At 0% it's the original size, a small thump at 14%, back to the original size at 28%, a bigger thump at 42%, and from 70% it holds the original size until the next beat.

Dividing the intervals this way completes a "small thump — big thump — rest" pattern within one cycle, and infinite keeps repeating that whole cycle to produce a rhythm close to a real pulse. Change the scale amount or the duration and the feel of the rhythm changes with it.

Check it with our tool. Instead of fine-tuning each percentage and scale value by hand, pick a preset and move the sliders — the keyframes code for the same principle is generated right away.

CSS Pulse & Heartbeat Animation Generator

Free · no sign-up · pick a preset and copy the CSS code right away

Common snags

SituationCause / fix
The animation plays once and stopsanimation-iteration-count defaults to 1 — set it to infinite to keep it repeating
It grows off-center instead of from the middleThe transform origin is off because of the element's or its parent's layout (alignment)
The enlarged part looks cut offCheck whether a parent element wrapping the badge has overflow: hidden
It looks like a single beat instead of a heartbeatThe keyframes are a simple pulse with only 0%, 50%, and 100% — add intermediate intervals

As the table shows, most problems come from missing the iteration count, a parent's overflow setting, or the number of keyframe intervals. Check them one at a time and most issues clear up right away.

The takeaway

An endlessly beating notification badge isn't a JavaScript timer — it's the power of animation-iteration-count: infinite alone. The growing and shrinking comes from scale values at each @keyframes interval, and the double-beat heartbeat rhythm comes from placing two expansion points within one cycle.

Once you know the principle, you can adjust the percentage intervals and scale values yourself to build the rhythm you want. If you'd rather not work out the numbers by hand each time, it's faster to start from a preset and fine-tune with sliders.

CSS Pulse & Heartbeat Animation Generator

Free · no sign-up · pick a preset and copy the CSS code right away

Frequently asked questions

Can I make the animation play just once and stop?

Yes. Set animation-iteration-count to the number of times you want (say, 3) instead of infinite, and it plays that many times and stops. If you want it to run only when a certain event happens, leave the class off by default and add it only when you need it — CSS still handles the repeating itself.

What's the difference between animating width or height and using transform: scale?

Changing width or height triggers layout recalculation (reflow), which is costly on every frame and can even shift the positions of nearby elements. transform: scale is handled only on a graphics layer and doesn't affect layout, which makes it a good fit for elements that move often, like badges.

How is the heartbeat preset different from the basic pulse?

The basic pulse is a simple curve that grows and shrinks once per cycle. The heartbeat preset puts a small expansion and a big expansion in order within one cycle, reproducing the double-beat feel of a real pulse.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. CSS shine effect: how to make a diagonal light sweepBuild a diagonal light sweep for premium cards and CTA buttons with pure CSS linear-gradient angles, plus how to tune angle, speed, and brightness.
  2. CSS shine effect: how a diagonal light sweep worksSee how a CSS shine effect works: a narrow gradient band, a gradient angle, an oversized pseudo-element, and overflow: hidden to cut it to the card.
  3. CSS Diagonal Stripes: One Line of CSS, No Image FilesHow repeating-linear-gradient draws diagonal stripe backgrounds without image files, and how angle and color stops control the pattern.
  4. text-shadow: How to Make 3D Letters With Two LayersWhy a single text-shadow looks flat, and how stacking two shadows in opposite directions makes banner and logo text look raised, with the exact CSS.
  5. CSS Typing Effect: How Typewriter Text and Cursor Blinking WorkSee how a CSS width animation with steps() types text one character at a time, and how a separate blink animation makes the cursor flash.
  6. CSS typing text effect with steps() and ch units, explainedHow steps(N) easing and the ch unit build a pure-CSS typewriter effect, how to size width and steps, plus cursor timing and font caveats.

Related tools