Looping animation
Also called infinite animation or animation-iteration-count
An animation that plays more than once, either a set number of times or forever, set in CSS with animation-iteration-count.
import { motion, useReducedMotion } from 'motion/react';
export function InboxHeader({
syncing,
latestMessageId
}: {
syncing: boolean;
latestMessageId: string;
}) {
const reduceMotion = useReducedMotion();
return (
<header className='flex items-center justify-between border-b px-4 py-3'>
<h2 className='font-semibold'>Inbox</h2>
<div className='flex items-center gap-3'>
{syncing && (
<motion.span
role='status'
aria-label='Syncing'
// repeat: Infinity spins for as long as the sync runs.
animate={reduceMotion ? undefined : { rotate: 360 }}
transition={{ duration: 0.8, ease: 'linear', repeat: Infinity }}
className='size-4 rounded-full border-2 border-muted border-t-foreground'
/>
)}
<motion.span
// A new message id remounts the bell, which replays the ring.
key={latestMessageId}
// repeat: 2 adds two runs to the first, so it rings three times.
animate={reduceMotion ? undefined : { rotate: [0, 12, -12, 0] }}
transition={{ duration: 0.6, ease: 'easeInOut', repeat: 2 }}
className='origin-top'
aria-hidden
>
<svg
viewBox='0 0 24 24'
fill='none'
stroke='currentColor'
strokeWidth={2}
className='size-5'
>
<path d='M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9' />
<path d='M10.3 21a1.94 1.94 0 0 0 3.4 0' />
</svg>
</motion.span>
</div>
</header>
);
}Make the notification bell ring three times when a new message arrives, using a 600ms wiggle with animation-iteration-count: 3, then stop. Keep the loading spinner rotating forever at 800ms per turn with linear easing. Stop both animations when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Looping animation?
A looping animation repeats instead of stopping after one run. In CSS, animation-iteration-count sets how many times it plays: 1 by default, a number such as 3, or infinite. Motion for React uses a repeat option that counts the extra runs, so repeat: 2 plays three times in total and repeat: Infinity never stops.
Endless loops fit things that stand for ongoing work: spinners, skeleton shimmers, a pulsing live indicator. A small fixed count suits attention cues, such as a bell that rings three times when a message arrives and then rests.
Endless motion pulls the eye and can make some people feel unwell. Stop a loop once its job is done, pause it while it is off screen, and stop or slow it for people who prefer reduced motion. Accessibility guidelines (WCAG) ask for a way to pause motion that starts on its own and lasts more than five seconds.
Often confused with
- Yoyo animation
- A yoyo animation is a loop that reverses direction on every other run. A plain loop restarts from the beginning each time.
Related terms
All termsYoyo animation
A looping animation that plays forward and then backward, so it moves back and forth smoothly instead of jumping back to the start.
Spinner
A small looping animation, usually a rotating ring, that shows the app is busy with a short task of unknown length.
Pulse animation
A soft, repeating beat or expanding ring that draws the eye to a live status, a new notification, or something that needs attention.
Reduced motion
An operating system setting that asks apps to minimize movement, which websites detect with the prefers-reduced-motion media query.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.