Codectionary / Developer documentation / HTML

<embed> and <object>

The <embed> and <object> elements embed external content — like PDFs, other HTML pages, or browser plugins — into a document. <object> is the more capable and standards-based of the two, supporting fallback content between its tags, while <embed> is simpler but has no fallback mechanism. Modern use cases increasingly favor <iframe> for HTML content and dedicated elements like <img>, <video>, or <picture> where applicable.

Syntax

<object data="file.pdf" type="application/pdf" width="600" height="400"></object>

Examples

Embedding a PDF

Displaying a PDF file directly in the page using object.

<object data="/docs/guide.pdf" type="application/pdf" width="100%" height="500">
  <p>Your browser cannot display PDFs. <a href="/docs/guide.pdf">Download it instead</a>.</p>
</object>

Embedding with embed

A simpler embed of a PDF with no fallback content.

<embed src="/docs/report.pdf" type="application/pdf" width="100%" height="500">

Embedding an SVG File as an Object

Loading an external SVG file as interactive content.

<object data="/icons/logo.svg" type="image/svg+xml" width="120" height="120"></object>

Attributes

  • data (URL): Used on object; the URL of the resource to embed
  • src (URL): Used on embed; the URL of the resource to embed
  • type (string): The MIME type of the embedded resource
  • width (number): Display width in pixels
  • height (number): Display height in pixels

Best practices

  • Prefer object over embed when you need fallback content for unsupported browsers
  • For embedding other web pages specifically, use iframe instead, which is more widely supported and flexible
  • Always provide a direct download link as a fallback when embedding documents like PDFs
  • Test embedded content across browsers, since plugin-dependent behavior for embed/object varies more than other media elements

At a glance

Purpose
Structure and meaning for web content
File extension
.html · .htm
Runs in
Web browsers
Usually used with
CSS and JavaScript

Specifications & further reading

Related HTML documentation