<object>
Example
<object
data="report.pdf"
width="800" height="600"
></object><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 adataURL and atypeMIME 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.