<object>

Term side of the Card.
Topic: Media & Embedding
Unit title: <object>
Categories: Tag
Explanation side of the Card

Explanation: The element that is used to embed multimedia elements such as images, videos or interactive content like PDFs. It can also serve as a fallback for content that browsers cannot natively support.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 3.
Availability: 

Example

Wronghtml
<object
  data="report.pdf"
  width="800" height="600"
></object>
Righthtml
<object data="report.pdf" type="application/pdf" width="800" height="600">
  <a href="report.pdf">Download the report (PDF)</a>
</object>

Content inside <object> shows when the browser cannot render the file, so users can still get it.

Common mistakes

  • Leaving <object> empty, so users see a blank box when the browser cannot display the file.

Key points

  • The <object> has a data URL and a type MIME type.
  • Fallback content, such as a download link, is placed inside the <object>.
  • Plain images and icons use <img>, not <object>.

Interview questions

What is the difference between object and img for SVG?

An SVG in <object> can run its own scripts and be styled as a document. In <img> it is a static image with no scripts.

What is the difference between object and iframe?

Both embed resources, but <object> supports fallback content inside it, while <iframe> is meant for HTML pages.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy