A heart monitor trace: a bright segment with a softer tail runs along an ECG line with one sharp beat. Drawn in SVG with stroke-dasharray and pathLength, so the timing survives any resize.
Also known as: ekg line animation, heart rate monitor loader, pulse line animation css.
<div class="ldr-ecg-heartbeat-line" role="status" aria-label="Loading">
<svg viewBox="0 0 120 40" aria-hidden="true">
<path class="ldr-ecg-heartbeat-line-track" pathLength="100" d="M2 23 H34 L38 18 L42 23 H48 L52 30 L58 4 L64 36 L68 23 H76 Q82 13 88 23 H118" />
<path class="ldr-ecg-heartbeat-line-tail" pathLength="100" d="M2 23 H34 L38 18 L42 23 H48 L52 30 L58 4 L64 36 L68 23 H76 Q82 13 88 23 H118" />
<path class="ldr-ecg-heartbeat-line-head" pathLength="100" d="M2 23 H34 L38 18 L42 23 H48 L52 30 L58 4 L64 36 L68 23 H76 Q82 13 88 23 H118" />
</svg>
</div>.ldr-ecg-heartbeat-line {
--s: var(--ldr-size, 48px);
--c: var(--ldr-color, #3b82f6);
width: calc(var(--s) * 2.4);
height: calc(var(--s) * 0.8);
}
.ldr-ecg-heartbeat-line svg {
display: block;
width: 100%;
height: 100%;
overflow: visible;
fill: none;
stroke-width: 3.5;
stroke-linecap: round;
stroke-linejoin: round;
}
.ldr-ecg-heartbeat-line-track { stroke: color-mix(in srgb, var(--ldr-color, #3b82f6) 16%, transparent); }
.ldr-ecg-heartbeat-line-tail {
stroke: color-mix(in srgb, var(--ldr-color, #3b82f6) 45%, transparent);
stroke-dasharray: 45 100;
animation: ldr-ecg-heartbeat-line-tail 1.8s linear infinite;
}
.ldr-ecg-heartbeat-line-head {
stroke: var(--c);
stroke-dasharray: 18 127;
animation: ldr-ecg-heartbeat-line-head 1.8s linear infinite;
}
@keyframes ldr-ecg-heartbeat-line-tail {
from { stroke-dashoffset: 45; }
to { stroke-dashoffset: -100; }
}
@keyframes ldr-ecg-heartbeat-line-head {
from { stroke-dashoffset: 18; }
to { stroke-dashoffset: -127; }
}
@media (prefers-reduced-motion: reduce) {
.ldr-ecg-heartbeat-line, .ldr-ecg-heartbeat-line *, .ldr-ecg-heartbeat-line::before, .ldr-ecg-heartbeat-line::after, .ldr-ecg-heartbeat-line *::before, .ldr-ecg-heartbeat-line *::after {
animation-duration: 3s;
}
}--ldr-color on the element or a parent.
Currently previewing #3b82f6.--ldr-size. Every dimension in the snippet is
derived from it. Currently previewing 64px.animation shorthand.
Delays on the children are relative, so they keep their rhythm.role="status" and an
aria-label so screen readers announce the wait. The reduced-motion rule
at the end slows the animation for users who asked for less motion.