🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEhtml

html Documentation

LOADING ENGINE...

autoplay

AI & DATA SCIENCE // autoplay

The autoplay attribute on <video> or <audio> starts playback automatically as soon as the media can begin playing, without user interaction.

Syntax

<video autoplay muted>
  <source src="background.mp4" type="video/mp4">
</video>

Deep Dive Course

**`autoplay`** is a boolean attribute that tells the browser to start playback as soon as enough data has loaded, with no click required from the user. Almost every modern browser (Chrome, Firefox, Safari) enforces a policy that **blocks autoplay with sound** entirely — the media simply won't autoplay unless it's also `muted`. This restriction exists specifically to stop unwanted, disruptive audio from playing the instant a page loads.

1Understanding autoplay

`autoplay` is a boolean attribute that tells the browser to start playback as soon as enough data has loaded, with no click required from the user. Almost every modern browser (Chrome, Firefox, Safari) enforces a policy that blocks autoplay with sound entirely — the media simply won't autoplay unless it's also muted. This restriction exists specifically to stop unwanted, disruptive audio from playing the instant a page loads.

💡

Don't rely on autoplay firing reliably even when muted — some browsers still block it under certain conditions (e.g. low battery mode, or if the user has a site-level autoplay-block setting), so always provide visible controls as a fallback.

editor.html
<video autoplay muted loop playsinline>
  <source src="/hero-background.mp4" type="video/mp4">
</video>
localhost:3000

2Practical Example

Here is a real-world application of autoplay showing how it is used in production HTML.

editor.html
<!-- Unmuted autoplay: silently ignored by the browser -->
<audio autoplay>
  <source src="/welcome.mp3" type="audio/mpeg">
</audio>
localhost:3000

3Best Practices

Follow these guidelines when working with autoplay:

1. Always pair autoplay with muted — unmuted autoplay is blocked by virtually every modern browser

2. Add playsinline as well for autoplaying video to work correctly on mobile Safari

3. Provide visible controls as a fallback in case autoplay is blocked in a given browser/context

⚠️

Tip: Don't rely on autoplay firing reliably even when muted — some browsers still block it under certain conditions (e.g. low battery mode, or if the user has a site-level autoplay-block setting), so always provide visible controls as a fallback.

editor.html
<video autoplay muted loop playsinline>
  <source src="/hero-background.mp4" type="video/mp4">
</video>
localhost:3000

Examples

Example 01Basic Usage
<video autoplay muted loop playsinline>
  <source src="/hero-background.mp4" type="video/mp4">
</video>
Example 02Advanced Example
<!-- Unmuted autoplay: silently ignored by the browser -->
<audio autoplay>
  <source src="/welcome.mp3" type="audio/mpeg">
</audio>

Best Practices

  • Always pair autoplay with muted — unmuted autoplay is blocked by virtually every modern browser
  • Add playsinline as well for autoplaying video to work correctly on mobile Safari
  • Provide visible controls as a fallback in case autoplay is blocked in a given browser/context

Interview Question

Why might a <video autoplay> element simply fail to start playing on page load?

Hint: Think about the browser's autoplay policy and what attribute is missing.

The most common reason is that the video isn't also muted — nearly every modern browser blocks autoplay for any media with sound, silently ignoring the autoplay attribute rather than erroring. Adding the muted attribute alongside autoplay is required for it to reliably work; on mobile Safari specifically, playsinline is also needed, or the browser may force the video to open in fullscreen instead of playing inline.

Exercises

EasyPractice using autoplay in a real scenario.
View Solution
<video autoplay muted loop playsinline>
  <source src="/hero-background.mp4" type="video/mp4">
</video>

Frequently Asked Questions

Why might a <video autoplay> element simply fail to start playing on page load?

The most common reason is that the video isn't also muted — nearly every modern browser blocks autoplay for any media with sound, silently ignoring the autoplay attribute rather than erroring. Adding the muted attribute alongside autoplay is required for it to reliably work; on mobile Safari specifically, playsinline is also needed, or the browser may force the video to open in fullscreen instead of playing inline.

Related Functions

video-tagaudio-tagmutedloop