The HTML <object> tag
The HTML <object> element embeds an external resource — commonly a PDF — using the data attribute for the URL and type for its MIME type. Content between the tags is shown as a fallback. For web pages, an <iframe> is usually the better choice.
Overview
The <object> element embeds an external resource and lets the browser choose an appropriate handler based on its type. In modern HTML its most common job is embedding a PDF inline in the page.
Anything you place between the opening and closing tags is fallback content, shown when the resource cannot be displayed — a useful place for a download link to the file. You rarely need <object> otherwise: use an <img> for images, <video> / <audio> for media, and an <iframe> for web pages.
Its old plugin-related attributes (for Flash, Java applets and the like) are obsolete now that browser plugins are gone, so treat <object> as a niche tool for the cases its modern replacements do not cover.
Syntax
<object data="file.pdf" type="application/pdf" width="600" height="400">
<a href="file.pdf">Download the PDF</a>
</object>
Attributes
The <object> element supports the following attributes, in addition to the global attributes available to every HTML element.
| Attribute | Value | Description |
|---|---|---|
data |
A URL pointing to the resource. | Sets the URL of an embedded object. |
form |
The id of a <form> element. |
Associates a control with a form by id. |
height |
A non-negative integer (pixels). | Sets the height of the element in pixels. |
name |
A string (the field name used in the submitted data). | Names a form control for submission. |
type |
A MIME type, e.g. application/pdf. |
Sets the MIME type of an embedded object. |
usemap |
A hash-prefixed map name, e.g. #planets. |
Links an image to a client-side image map. |
width |
A non-negative integer (pixels). | Sets the width of the element in pixels. |
Example
<object data="https://codeshack.io/web/img/icon.png" type="image/png" width="64" height="64"><a href="https://codeshack.io/">Fallback link</a></object>
Best practices
Frequently asked questions
What is the object element for?
How do I embed a PDF in HTML?
<object data="file.pdf" type="application/pdf"> with a download link as fallback content, or an <iframe>.