Français

<object>

Embed a generic external resource

  • HTML
  • accessibility
  • semantics

<object> — The embedded resource

The <object> element embeds a generic external resource into the page: PDF, image, or historically Flash and Java applets. Today, prefer <iframe> for documents and <video> or <audio> for media.

When to use it

You want to embed a PDF directly in the page and provide a fallback link if the browser cannot display it. You cannot find a specialized element (<iframe>, <video>, <img>, <audio>) that matches your resource. This is rare in a modern project.

What you gain

Accessibility: the fallback content between the opening and closing tags is read by assistive technologies if the resource fails to load. Without this fallback, the user has no idea what they are missing.

Code example

<object
  data="/documents/report.pdf"
  type="application/pdf"
  width="100%"
  height="600"
>
  <p>
    Your browser cannot display this PDF.
    <a href="/documents/report.pdf">Download the report</a>.
  </p>
</object>

Further reading