The autoplay attribute is a small instruction attached to an HTML element. Its job is to ask the browser to start media without user input. It is easier to remember when you can see it in a real piece of markup.
What autoplay is used for
Ask the browser to start media without user input. The attribute appears inside an element’s opening tag. Depending on its definition, it may take a specific string, a number, an enumerated keyword, or be a boolean attribute.
The example below uses it in a video context. Other elements may support it too, or may give the same attribute a different meaning.
Example you can try
<video controls autoplay muted playsinline width="640">
<source src="lesson.mp4" type="video/mp4">
<p>Video unavailable.</p>
</video>
How the example works
Look for autoplay in the snippet. Here the example shows its presence without a string value. This is a concrete input the browser can interpret; it is not just text shown to the reader.
Autoplay with sound is often blocked. The example adds muted and playsinline, but you should still let visitors choose when media starts.
Values and important behavior
Use the value format shown by the HTML definition. Do not assume that a value accepted in one attribute also works in another. When a browser ignores an invalid value, inspect the element and correct the markup.
This detail matters most when the page receives user input, navigates to another document, or loads an external resource. In those cases, check the browser behavior and any server-side requirements separately.
Small practice task
Copy the code and change autoplay to another sensible value, or remove it entirely if it is optional. Test the difference in the browser and inspect any submitted value or network request.
Common Beginner Mistakes
- Autoplay with sound is often blocked. The example adds muted and playsinline, but you should still let visitors choose when media starts.
- Using
autoplayon an element that does not support it. - Believing that an HTML hint or client-side check replaces real server validation or a security policy.
Key Takeaways
autoplayis used to ask the browser to start media without user input.- Autoplay with sound is often blocked. The example adds muted and playsinline, but you should still let visitors choose when media starts.
- Choose valid values and test the result instead of guessing what the browser will do.