HTML loop Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The loop attribute is a boolean attribute on <video> and <audio>. When present, the player seeks back to the start when the media reaches the end — so playback repeats.

Pair it with controls so users can pause. For decorative background clips, combine with autoplay and muted (audible autoplay is often blocked).

Baseline · Widely available.

Not deprecated and not experimental on audio/video. Stable across modern browsers since about July 2015.

Offer a way to stop.

Looping motion or sound can distract or overwhelm. Keep controls (or another pause control) so users can stop playback.

HTML Syntax

syntax.html
<video|audio loop>

Boolean attribute: write loop alone. loop="false" does not disable it — remove the attribute entirely.

Attribute Values

loop has no keyword list. Presence means repeat; omission means play once:

Value / pairingDescriptionTry it
loop (present)When the media ends, seek to the start and continueTry it
OmittedPlay once, then stop (default)Try it
loop + controlsRepeat with a visible pause/play UITry it
On <audio>Same boolean behavior for soundTry it
+ autoplay + mutedCommon muted background / hero loop patternTry it

Live Preview

Toggle loop, then press play. With loop on, the clip restarts at the end instead of stopping.

Options

Sample clip from /video/count.mp4. Let it reach the end to see looping.

Video

loop + muted

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Looping Video with Controls

Repeat a short clip and keep the browser’s play/pause UI available.

HTML
<video width="400" height="225" controls loop>
  <source src="/video/count.mp4" type="video/mp4">
  Your browser does not support the video element.
</video>
Try It Yourself

How It Works

  1. loop tells the player to seek to the start when the clip ends.
  2. controls shows play, pause, and seek so users stay in control.
  3. <source> points at the media file (here MP4).
  4. Fallback text appears only if the browser cannot play video.

Example 2 — Looping Audio

Same boolean on <audio>. Provide multiple sources for broader codec support.

HTML
<audio controls loop>
  <source src="/audio/count.mp3" type="audio/mpeg">
  <source src="/audio/count.ogg" type="audio/ogg">
  Your browser does not support the audio element.
</audio>
Try It Yourself

How It Works

  1. loop on audio restarts the track after the last sample.
  2. Two <source> files let the browser pick MP3 or OGG.
  3. controls is important — looping sound without pause is poor UX.
  4. User starts playback with the play button (no autoplay here).

Example 3 — Muted Autoplay Hero Loop

Silent background-style video: autoplay, muted, looping, with controls for pause.

HTML
<video
  width="400"
  height="225"
  autoplay
  muted
  loop
  playsinline
  controls
  poster="/images/html-loop-attribute.webp">
  <source src="/video/count.mp4" type="video/mp4">
  Your browser does not support the video element.
</video>
Try It Yourself

How It Works

  1. muted + autoplay usually pass browser autoplay policies.
  2. loop keeps the clip repeating for a continuous background feel.
  3. playsinline helps iOS Safari play in place instead of forcing fullscreen.
  4. poster shows a still until the first frame is ready.

Edge Cases & Pitfalls

Most mistakes are boolean traps, confusing loop with autoplay, or leaving no pause control.

boolean

loop="false" still loops

Presence of the attribute means true. Delete loop entirely to play once.

autoplay

Loop does not start playback

loop only restarts after the end. Use autoplay (usually with muted) if you need an automatic start.

a11y

Always allow pause

Continuous motion or sound needs a stop path. Keep controls or provide an equivalent control.

marquee

Not the old marquee loop

Deprecated <marquee loop="…"> used a scroll-count number. That element is obsolete — do not use it. Media loop is a separate, modern boolean.

cost

Bandwidth and battery

Endless loops keep decoding media. Prefer short clips, and let users pause — especially on mobile.

Browser Support

loop is an HTML attribute on media elements in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

loop

Widely available on audio and video since about July 2015. When present, conforming players restart media at the end.

97% Global support (approx.)
Google Chrome 3+
Full support
Mozilla Firefox 11+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 10.5+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 9+
Supported
loop Widely supported

Bottom line: Safe to use on audio and video everywhere. Always pair looping media with a way for users to pause.

Key Takeaways

  • Role: boolean on audio/video that restarts media when it ends.
  • Not autoplay: loop repeats; autoplay starts without a Play click.
  • Controls matter: keep pause/play available on looping media.
  • Boolean trap: presence = on; loop="false" still means on.

One line: loop repeats media at the end — add controls, and mute if you also autoplay.

Frequently Asked Questions

On audio or video, loop is a boolean attribute. When present, the browser seeks back to the start when playback reaches the end, so the media repeats.
The HTML audio and video elements. Do not confuse this with the obsolete marquee loop attribute, which used a number of scroll times.
No. loop is a boolean attribute. If it is present at all, looping is on. Remove the attribute entirely to play once.
No. autoplay starts playback without a Play click. loop only restarts after the media ends. They are often combined for background clips.
Yes when possible. Continuous motion or sound needs a clear way to pause. Prefer the controls attribute or an equivalent pause control.
No. On audio and video it is standard and widely supported. The old marquee element and its loop attribute are deprecated — avoid marquee.

Next: low

Learn the low attribute on meter for gauge ranges.

low tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful