HTML Reference ยท Embedded Content
The <embed> element
Reference for the HTML <embed> element: src, type, width and height, how browsers handle PDFs, images and HTML today, and why <iframe> or <object> are often better.
The <embed> element inserts an external resource into the page at the point where the tag appears. It was created for browser plug-ins such as Flash. Plug-ins are gone from every modern browser, so today <embed> can only show what the browser handles itself: images, SVG, HTML pages and, in desktop browsers with a built-in viewer, PDF files.
<embed> is a void element with no fallback content. If the resource can't be shown, the user sees an empty box (or nothing).
<embed src="/files/menu.pdf" type="application/pdf" width="600" height="800">
Try it
For an image like this, an <img> with alt text is the better choice; the example only shows how <embed> behaves.
Attributes
| Attribute | Values | Description |
|---|---|---|
src |
URL | The resource to embed. |
type |
MIME type | The resource's media type, such as application/pdf or image/svg+xml. Helps the browser decide how to handle it. |
width |
Non-negative integer | The width in CSS pixels. |
height |
Non-negative integer | The height in CSS pixels. |
It also accepts the global attributes. Historically, any other attribute was passed through to the plug-in as a parameter; with plug-ins gone, those extra attributes do nothing.
Usage notes
- Prefer a more specific element. Use
<img>for images,<video>and<audio>for media, and<iframe>for other web pages. They offer fallbacks, accessibility hooks and better control. - PDFs. Desktop browsers show PDFs with their built-in viewer; many mobile browsers don't. Always give a normal download link next to the embed, for example
<a href="/files/menu.pdf">Download the menu (PDF)</a>. - No fallback, no
alt. Unlike<object>,<embed>can't hold fallback content. Add atitleor nearby text that describes the content so assistive technology users know what it is. - Sizing. Without
widthandheight, browsers use a small default box (often 300 ร 150 pixels). Set the size in attributes or CSS. - Security. Content from another origin is isolated the same way as in an iframe, but
<embed>has nosandboxattribute. To restrict what embedded HTML can do, use an<iframe sandbox>.
Technical summary
| Content categories | Flow content, phrasing content, embedded content, interactive content, palpable content |
| Permitted content | Nothing; it is a void element |
| Tag omission | Start tag required; must not have an end tag |
| Permitted parents | Any element that accepts embedded content |
| Implicit ARIA role | No corresponding role |
| DOM interface | HTMLEmbedElement |
| Default display | inline (a replaced element) |
Browser support
Supported in every browser; what it can display depends on the browser's built-in handlers, since plug-ins (Flash, Java and others) are no longer supported anywhere.
Related
<object>โ an embed with fallback content<iframe>โ a nested web page with a sandbox<img>โ images- Lesson: Embedding Content
- Lesson: Deprecated Elements