HTML autoplay Attribute

Beginner
⏱️ 4 min read
📚 Updated: Jun 2026
🎯 2 Examples
Media

Introduction

The autoplay attribute is an essential feature in HTML that allows developers to control the automatic playback of audio and video elements. This attribute can enhance the user experience by providing seamless multimedia content without requiring manual intervention.

What You’ll Learn

01

Boolean

Presence = play.

02

video / audio

Media elements.

03

muted

Browser policy.

04

controls

User pause/volume.

05

JavaScript

.autoplay = true

06

Best Use

Use responsibly.

Purpose of autoplay

The primary purpose of the autoplay attribute is to specify whether a media element should start playing automatically when the page loads. This can be particularly useful for background music, promotional videos, or any other scenario where immediate playback is desired.

💡
Pair with muted for Reliability

Modern browsers often block autoplay with sound. Add muted (and playsinline on mobile) when silent autoplay is acceptable.

📝 Syntax

Add the boolean autoplay attribute to a <video> or <audio> element:

autoplay.html
<video controls autoplay muted playsinline>
  <source src="clip.mp4" type="video/mp4">
</video>

Syntax Rules

  • Boolean attribute—presence means playback should start automatically.
  • Valid on <video> and <audio> elements.
  • Omit the attribute entirely to use default non-autoplay behavior.
  • Combine with controls so users can pause or adjust volume.

💎 Values

The autoplay attribute accepts a boolean value:

  • autoplay (present) — Indicates that the media should start playing automatically.
  • true (JavaScript property) — Another way of specifying that the media should start playing automatically when set via script.
  • false (JavaScript property or omitted attribute) — Specifies that the media should not start playing automatically. This is the default behavior if the autoplay attribute is not present.
⚠️
HTML vs JavaScript

In HTML markup, boolean attributes are enabled by their presence. To disable autoplay in HTML, remove the attribute—do not rely on autoplay="false", which can still be treated as enabled in some cases.

autoplay-values.html
<!-- HTML: presence enables autoplay -->
<video autoplay muted></video>

<!-- JavaScript property -->
<script>
  videoElement.autoplay = true;
  videoElement.autoplay = false;
</script>

⚡ Quick Reference

ScenarioRecommended MarkupNotes
Silent hero videoautoplay muted playsinlineWorks in most browsers
Video with soundNo autoplay; use controlsRequires user gesture
Background audioautoplay loop mutedProvide mute toggle
Dynamic autoplayelement.autoplay = trueCall load() after change
User controlcontrolsAlways recommended
Applicable elementsvideo, audioHTML media elements

Applicable Elements

ElementSupported?Notes
<video>YesMost common use
<audio>YesBackground music, podcasts
<iframe>NoUse embed-specific APIs
<img>NoNot a media element

Examples Gallery

Video autoplay example and dynamic JavaScript autoplay.

👀 Live Preview

Muted video set to autoplay on page load:

Example

Let’s look at a simple example of how to use the autoplay attribute in an HTML video element:

autoplay.html
<video controls autoplay muted playsinline>
  <source src="example.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>
Try It Yourself

How It Works

In this example, the autoplay attribute is included within the <video> element, indicating that the video should start playing automatically when the page loads. Adding muted helps browsers allow autoplay without a prior user click.

Dynamic Values with JavaScript

You can dynamically control the autoplay attribute using JavaScript. This is particularly useful when you want to adjust the autoplay behavior based on certain conditions or user interactions. Here’s an example:

dynamic-autoplay.html
<video id="dynamicVideo" controls muted>
  <source src="example.mp4" type="video/mp4">
</video>

<script>
  // Dynamically set autoplay for a video element
  var videoElement = document.getElementById("dynamicVideo");
  videoElement.autoplay = true;
  videoElement.load();
</script>
Try It Yourself

How It Works

In this script, the autoplay property is dynamically set to true for a video element with the id dynamicVideo. Calling load() refreshes the media element so the new autoplay setting can take effect.

♿ Accessibility

  • Avoid surprise audio — Autoplay with sound can disorient users and screen reader users.
  • Provide controls — Always include controls so users can pause, mute, or adjust volume.
  • Respect preferences — Consider users with vestibular disorders; avoid flashing autoplay loops without warning.
  • Offer alternatives — Do not rely on autoplay alone to convey essential information.
  • Test with reduced motion — Some users prefer less automatic movement on pages.

🧠 How autoplay Works

1

Author adds autoplay

Mark a video or audio element with the boolean attribute.

Markup
2

Browser loads media

The file downloads and the media element becomes ready.

Load
3

Playback policy check

Browser allows muted autoplay more readily than autoplay with sound.

Policy
=

Media starts playing

Playback begins without the user pressing play first.

Browser Support

The autoplay attribute is supported in all modern browsers, but autoplay behavior may be restricted—especially for media with sound until the user interacts with the page.

HTML5 · Fully supported

Universal autoplay attribute

All major browsers recognize autoplay on media elements.

99% Attribute support
Google Chrome Muted autoplay allowed
Policy restricted
Mozilla Firefox Muted autoplay allowed
Policy restricted
Apple Safari Requires muted / playsinline
Policy restricted
Microsoft Edge Muted autoplay allowed
Policy restricted
autoplay attribute 99% supported

Bottom line: The attribute is widely supported, but test muted autoplay and always provide user controls.

💡 Best Practices

✅ Do

  • Use autoplay sparingly on intentional hero or promo media
  • Pair with controls so users can pause or adjust volume
  • Use muted and playsinline for reliable silent autoplay
  • Test autoplay in Chrome, Firefox, and Safari
  • Respect browser autoplay policies and user preferences

❌ Don’t

  • Autoplay loud audio unexpectedly on page load
  • Assume autoplay with sound works without user interaction
  • Hide controls when media autoplays
  • Use autoplay="false" in HTML to disable (remove the attribute instead)
  • Autoplay essential content users cannot easily pause
  • Use the autoplay attribute responsibly, as automatic playback can be intrusive and affect the user experience negatively.
  • Consider providing user controls (controls attribute) alongside autoplay to allow users to pause or adjust the volume of the media.
  • Be aware that some browsers may have restrictions on autoplay to prevent unwanted noise or disruption, especially if the page is not interacted with by the user.

Conclusion

The autoplay attribute is a powerful tool for controlling the automatic playback of audio and video elements in HTML. By understanding how to use this attribute and considering best practices, you can create engaging multimedia content on your web pages.

Use muted autoplay when immediate silent playback is appropriate, always provide controls, and reach for JavaScript when autoplay depends on user actions or runtime conditions.

Key Takeaways

Knowledge Unlocked

Five truths every developer should know about autoplay

Bookmark these before adding auto-playing media to your site.

5
Core concepts
🎬 02

video / audio

Media only.

Scope
🔇 03

muted

Policy friendly.

Browser
⚙️ 04

.autoplay

Dynamic JS.

Script
05

controls

User choice.

A11y

❓ Frequently Asked Questions

It tells the browser to start playing audio or video automatically when enough media data is available.
<video> and <audio> elements.
Browsers block autoplay with sound until the user interacts with the page. Use muted for silent autoplay or wait for a user click before calling play().
Remove the autoplay attribute from the element. In JavaScript, set element.autoplay = false.
Yes. Set videoElement.autoplay = true and call load() to refresh the media element.
Yes. Controls let users pause, mute, or adjust volume when media starts automatically.

Add responsible auto-playing media

Practice the autoplay attribute with video and dynamic JavaScript examples in the Try It editor.

Try video example →

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.

5 people found this page helpful