<embed> in HTML: embedding external content with no fallback

The <embed> tag embeds external content usually driven by a plugin, but stays empty and offers no fallback content if it fails to load.
4 min read
Believemy logo

A third-party service sometimes gives you a small snippet to paste onto your page to display content it hosts itself: a PDF viewer with its own controls, or historically a module handled by a browser plugin, like Flash or Java. You then need a tag that says "show whatever this plugin or viewer can render here", without you having to rebuild the interface yourself.

That is the role of <embed>: it embeds an external resource, generally handed off to a plugin or a viewer built into the browser, as a single tag with no content and no closing tag.


Definition

<embed> is a tag that embeds external content usually handled by a browser plugin or a rendering engine specific to the file type. Historically it was mostly used to display Flash animations or Java applets; today it shows up more for PDFs or certain media formats the browser can open natively.

It is an empty element: it takes no content between an opening and a closing tag, it is written all in one go, with its attributes, and therefore has no built-in way to show a replacement message if the resource fails to load.


Syntax and attributes

Three attributes usually suffice: src for the resource's address, type to specify its format, and width/height to reserve the space it will occupy on screen.

AttributeRole
srcAddress of the external resource to load
typeMIME type of the content, for example application/pdf
width, heightDimensions reserved for display


Concrete example

Here is how to embed a PDF preview directly on a page, with its dimensions set in advance.

HTML
<embed src="brochure.pdf" type="application/pdf" width="600" height="400" />

Notice the absence of a closing tag: the whole definition fits on this single line, which is both the simplicity and the limitation of <embed>.


Difference with object

The key difference comes precisely from that lack of content. <object> is written with an opening and a closing tag, and everything placed between the two becomes fallback content, shown only if the primary resource cannot load. <embed>, being an empty element, cannot offer anything like that: if the plugin is missing, the format is unrecognized, or the resource fails to load, your visitors are left facing an empty space or a generic browser-imposed message, with no message you could have written yourself.

Trait<embed><object>
Fallback contentNone, empty elementYes, between the opening and closing tags
ClosingNo closing tagOpening and closing tag
Common useSimple PDFs, specific third-party widgetsPDFs, images, nested HTML documents


Best practices

Before reaching for <embed>, ask yourself whether fallback content actually matters to your visitors: a document essential to understanding the page almost always deserves <object>, which lets you write a useful message, or at least a direct download link. Reserve <embed> for cases where the external content provider explicitly requires it in their embed code, or when a more specific tag, like one for an image or a video, simply does not fit the format involved.

Good to know

Because <embed> offers no alternative text and no fallback content, a visitor using a screen reader, a browser blocking the required plugin, or a connection that fails to load the resource gets literally nothing in its place: no message, no explanation, just an empty space or the browser's default behavior. That is the central pitfall of this tag, worth remembering before using it for anything genuinely important.


Frequently asked questions

QuestionCan you add fallback text between the embed tag and its closing tag?

No, that is impossible: <embed> is an empty element, it has no closing tag and therefore cannot contain any text, image, or link. If fallback content matters to you, you need <object>, which was specifically designed for that purpose.

QuestionIs embed still useful today, now that Flash is gone?

Yes, but more rarely and for different cases than its historical use. It mostly shows up for displaying a PDF preview through the browser's built-in viewer, or for embedding a widget from a third-party service whose embed code specifically requires this tag. Most other needs today go through dedicated, more modern and more accessible tags.

QuestionWhat is the difference between embed and a plain image for showing a PDF?

An image can only display standard image formats, like a JPEG or a PNG: it cannot open a PDF document. <embed> can load a PDF and let the browser's built-in viewer render it with its own controls, like zooming or paging through the document, something a plain image will never offer.

Related terms

Discover our hTML and CSS glossary

Browse the terms and definitions most commonly used in HTML and CSS development.

Share this article

Want to help us? Share this article on your networks or even better: on your site, in an article or in your newsletter.