Av Prop Autoplay
## HTML Audio/Video DOM autoplay Property
The `autoplay` property sets or returns whether an audio or video should start playing immediately after it is loaded.
---
## Syntax
### Set the autoplay property:
```javascript
audioOrVideoElement.autoplay = true | false;
```
### Return the autoplay property:
```javascript
let isAutoplay = audioOrVideoElement.autoplay;
```
---
## Property Values
| Value | Description |
| :--- | :--- |
| `true` | The audio/video will start playing automatically as soon as it is loaded. |
| `false` | **Default**. The audio/video will not start playing automatically when loaded. |
---
## Technical Details
| Detail | Description |
| :--- | :--- |
| **Return Value** | A Boolean: `true` if the media is set to autoplay, otherwise `false`. |
| **Default Value** | `false` |
| **DOM Level** | HTML5 Media Element |
---
## Code Examples
### Example 1: Enabling Autoplay and Reloading the Video
This example demonstrates how to programmatically enable autoplay on a video element and reload it so the changes take effect immediately.
```javascript
// Select the video element by its ID
const myVid = document.getElementById("video1");
// Enable autoplay
myVid.autoplay = true;
// Reload the video to apply the autoplay setting
myVid.load();
```
### Example 2: Checking the Autoplay Status
You can also read the property to check if autoplay is currently enabled on a media element.
```javascript
const myAudio = document.getElementById("audio1");
if (myAudio.autoplay) {
console.log("The audio is configured to play automatically.");
} else {
console.log("Autoplay is disabled. The user must trigger playback.");
}
```
---
## Browser Compatibility and Considerations
All modern web browsers (including Chrome, Firefox, Safari, Edge, and Opera) support the `autoplay` property.
### Important Autoplay Policies
In modern web development, browsers enforce strict **Autoplay Policies** to improve user experience and prevent unwanted noise:
1. **Muted Autoplay:** Most browsers will only allow autoplay to function if the media element is muted (e.g., `
YouTip