embed
The HTML <embed> element places external content in a document. This page explains its void-element syntax, its limits, and why a more specific element is often a better choice.
What you will learn
- What the
embedelement is used for - Why it has no closing tag or fallback children
- Why accessibility, security, and a more specific alternative should be checked first
Basic syntax
<embed src="diagram.pdf" type="application/pdf">
embed is a void element, so it must not have a closing tag or child content. The src value identifies the external resource and type can describe its media type.
Prefer a specific element when one exists
- Image
- Use
imgwith useful alternative text. - Audio or video
- Use
audioorvideowith controls and an appropriate fallback. - Another document or interactive page
- Consider
iframe,object, or a normal link based on the content and trust boundary.
No fallback content inside embed
Unlike object, embed cannot contain fallback markup between an opening and closing tag. If users must still access the content when embedding fails, provide a nearby link or choose an element that supports a useful fallback.
<p>
<a href="diagram.pdf">Download the diagram as a PDF</a>
</p>
<embed src="diagram.pdf" type="application/pdf">
Security and privacy
Embedding external content gives that resource a place in your page and can affect privacy, performance, and security. Check the source, content type, permissions, and browser behavior. Do not embed untrusted content simply because a URL is available.
Common mistakes
- Writing a closing
</embed>tag or placing fallback text inside it. - Using
embedfor an image or video instead of its semantic element. - Providing no link or alternative when the external resource cannot load.
- Embedding third-party content without checking trust, privacy, and performance implications.