HTML Reference ยท Embedded Content
The <object> element
Reference for the HTML <object> element: data, type, name, form, width and height, nested fallback content, PDFs and SVG, obsolete attributes and technical details.
The <object> element embeds an external resource, such as an image, an SVG file, a PDF or another HTML page. Its special feature is fallback content: whatever you put between the tags is shown when the resource can't be loaded or displayed.
Like <embed>, it was designed for plug-ins (Flash, Java applets), which no longer exist in browsers. Today it can only display what the browser handles natively, so it is mostly used for PDFs and as a wrapper with a built-in fallback.
<object data="/files/report.pdf" type="application/pdf" width="600" height="800"> <p><a href="/files/report.pdf">Download the report (PDF)</a></p> </object>
Try it
The first object loads the SVG and ignores its content. The second fails, so the browser renders what is inside it.
Attributes
| Attribute | Values | Description |
|---|---|---|
data |
URL | The resource to embed. Required; must be a valid, non-empty URL. |
type |
MIME type | The resource's media type, such as application/pdf or image/svg+xml. |
name |
Text | A name for the object's browsing context, usable as a link target when it displays an HTML page. |
form |
ID of a <form> |
Associates the object with a form element elsewhere in the page. It has no effect on submission. |
width |
Non-negative integer | The width in CSS pixels. |
height |
Non-negative integer | The height in CSS pixels. |
It also accepts the global attributes. The attributes archive, classid, codebase, codetype, declare and standby, and the child element <param>, are obsolete; they only made sense for plug-ins.
Usage notes
- Always provide fallback content. A download link or a short description is the most useful fallback, especially for PDFs, which many mobile browsers can't show inline.
- Fallbacks can be nested. An
<object>inside another<object>is tried when the outer one fails, and plain text can be the last resort. - Prefer specific elements. For images use
<img>, for video and sound use<video>and<audio>, and for web pages use<iframe>, which supportssandboxandtitle-based accessibility well. - SVG with scripts. Unlike an SVG in
<img>, an SVG loaded through<object>can run its own scripts and its links work. Load only trusted SVG files this way. - Accessibility. Give the object a
titleor anaria-labeldescribing the content, and make sure the fallback says the same thing in words.
Technical summary
| Content categories | Flow content, phrasing content, embedded content, listed form-associated element, palpable content |
| Permitted content | Transparent (the fallback content) |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts embedded content |
| Implicit ARIA role | No corresponding role |
| DOM interface | HTMLObjectElement |
| Default display | inline (a replaced element when it shows a resource) |
Browser support
Supported in every browser; what it can display depends on the browser's built-in handlers, since plug-ins are no longer supported anywhere.
Related
<embed>โ embeds a resource without fallback<iframe>โ a nested web page<param>โ obsolete plug-in parameters<img>โ images- Lesson: Embedding Content
- Lesson: Deprecated Elements