<embed>

Embeds an external resource in the page, most often a PDF document.

Display
inline (replaced element)
Closing tag
None, void element
Permitted content
None, empty element
On this page

Example

#
HTML
<embed src="/pliki/plan-kursu-html.pdf" type="application/pdf" width="480" height="320">
<p><a href="/pliki/plan-kursu-html.pdf">Download the course outline (PDF)</a></p>

On a computer the browser shows a built-in PDF viewer here, with scrolling and zooming. On some phones an empty space remains, which is why the download link is essential.

Definition and usage

#

The <embed> element inserts external content into the page that the browser displays with its own tools, most often a PDF document in the built-in viewer. You give the address in src, the file type in type, and the size in width and height. It is an empty element with no closing tag.

In the past <embed> was used mainly for plugins such as Flash. Plugins have disappeared from browsers, so today this element has few uses. Insert images with <img>, videos with <video>, and other pages with <iframe>.

The biggest drawback of <embed> is the lack of fallback content. If the browser can’t display the file (for example a PDF on some phones), the user sees an empty space. That’s why it is always worth adding a plain download link next to it, or reaching for <object>, which supports fallback content.

Syntax

#
Syntax
<embed src="file.pdf" type="application/pdf" width="…" height="…">

Attributes

#
  • src

    URL

    The address of the embedded file.
  • type

    MIME type, e.g. `application/pdf`

    The type of the resource. It helps the browser choose how to display it before it even downloads the file.
  • width / height

    number of pixels

    The dimensions of the area in which the resource is displayed.

The element also supports all global attributes, such as class, id, style and hidden.

More examples

#
An image embedded with embed
HTML
<embed src="/collections/covers/programowanie-dla-dzieci.webp" type="image/webp" width="240" height="160">
Preview

It works, but for images <img> is better, because it has the alt alternative text and lazy loading.

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Always add a link to download the file next to it. <embed> has no fallback content, so this is the only help for people whose preview won’t work.
  • Use <iframe> to embed other pages, and for videos from video services, the <iframe> code provided by the service.

Related entries

#

Spotted a mistake or missing an example? Write to us.