👀 Live Preview
Short looping video (plays until you pause):
The loop attribute makes this clip restart when it ends. muted helps autoplay policies in some browsers.

The loop attribute is used on <audio> and <video> elements to make media restart automatically when it reaches the end. By default, audio and video play once and stop. With loop, playback repeats indefinitely until the user pauses it or JavaScript changes the setting. This is ideal for background clips, ambient sound loops, and short animations—not for programming loops in JavaScript.
Presence = repeat.
Media only.
Repeat vs start.
Let users pause.
Toggle at runtime.
Avoid annoyance.
loopThe primary purpose of the loop attribute is to specify whether a media element should automatically restart once playback finishes. Without loop, the media stops at the last frame or sample. With loop, the browser seeks back to the start and plays again seamlessly.
Common uses include looping background videos on landing pages, repeating short UI sound effects, and ambient audio tracks. Always pair looping media with user controls or a clear way to stop playback.
<video width="320" height="240" controls loop>
<source src="clip.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<audio src="ambient.mp3" controls loop></audio><video> and <audio> elements only.loop or loop=""; presence enables repeating playback.loop is false).loop over loop="true" (both work, but bare form is idiomatic HTML).controls so users can pause looping media.mediaElement.loop = true on HTMLMediaElement.The loop attribute is a boolean attribute:
loop present — Media repeats indefinitely after reaching the end (true).loop="" or loop="loop" — XHTML-style boolean; same as bare loop.document.getElementById("myVideo").loop = true;
document.querySelector("audio").loop = false;| Use Case | Markup | Notes |
|---|---|---|
| Looping video | <video loop controls> | Add controls for UX |
| Looping audio | <audio loop controls> | Ambient sounds |
| Background clip | loop muted playsinline | Often with autoplay |
| Disable loop | Omit loop | Or .loop = false |
| Custom repeat count | JS ended event | Not built into loop attr |
| Element | Supported? | Notes |
|---|---|---|
<video> | Yes | Primary use case |
<audio> | Yes | Music, sound effects |
<ul>, <ol> | No | Document lists, not media loop |
<marquee> (deprecated) | No | Different legacy feature |
loop vs autoplay| Feature | loop | autoplay |
|---|---|---|
| What it does | Repeats after end | Starts on page load |
| Requires user gesture? | No (for loop alone) | Often blocked without mute |
| Typical combo | loop muted playsinline autoplay | Background hero videos |
| Accessibility | Can annoy if no pause | Can surprise users |
Looping video, looping audio, and toggling loop with JavaScript.
Short looping video (plays until you pause):
The loop attribute makes this clip restart when it ends. muted helps autoplay policies in some browsers.
<video width="320" height="240" controls loop>
<source src="example.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>The boolean loop attribute tells the browser to restart playback at the ended event instead of stopping.
<audio src="ambient.mp3" controls loop></audio>loop on <audio> uses the same media pipeline as video—restart on end until paused or loop is set to false.
<video id="dynamicVideo" controls src="clip.mp4"></video>
<script>
document.getElementById("dynamicVideo").loop = true;
</script>The loop property on HTMLMediaElement mirrors the content attribute. Use it when looping should depend on user settings or app state.
prefers-reduced-motion: reduce is set.Normal playback.
Track reaches last frame.
Browser seeks to start.
Until user pauses or loop=false.
The loop attribute is supported in all modern browsers on <audio> and <video>. Behavior is consistent across Chrome, Firefox, Safari, and Edge.
All major browsers repeat audio and video when loop is set.
Bottom line: Safe to use on audio and video; test autoplay + loop combos on mobile Safari.
loop for short background clips and ambient audiocontrols or a visible pause buttonmuted playsinline for mobile background videoloop in JS when user changes preferencesloop="true" is required (bare loop is standard)<ul> or list elementsprefers-reduced-motion for decorative loopsThe loop attribute is a valuable addition to HTML for repeating audio and video playback. Whether you are incorporating background videos or ambient sound, boolean loop on media elements keeps content playing seamlessly.
Always consider user experience: provide controls, avoid surprise autoplay sound, and use JavaScript when looping should be optional. Combined with autoplay and muted, loop powers many modern hero sections—used responsibly.
loopBookmark these before adding repeating media.
loop = repeat
SyntaxMedia only
ElementsRepeat vs start
CompareToggle runtime
DynamicLet users pause
A11y<audio> or <video> restart automatically when playback reaches the end, repeating until paused or disabled.loop for idiomatic HTML. loop="true" works but is unnecessary for boolean attributes.ended event for a fixed repeat count.muted on mobile browsers.videoElement.loop = true or false on the media element.loop attribute is only for media elements. Programming loops use for, while, etc. in JavaScript.Practice loop on <video> and <audio> and toggle it with JavaScript in the Try It editor.
5 people found this page helpful