HTML <object> Element
The HTML <object> element embeds an external resource within a webpage and can include alternative content when the resource cannot be displayed.
Syntax
<object data="resource.ext" type="media/type">
Fallback content
</object>
The <object> element requires both an opening and closing tag. The data attribute identifies the resource to load, while content placed between the tags can provide a fallback when the resource cannot be displayed.
Attributes
The <object> element supports the global HTML attributes and the following element-specific attributes:
| Attribute | Description |
|---|---|
data |
Specifies the URL of the external resource to embed. |
type |
Specifies the MIME type of the resource identified by the data attribute. |
name |
Assigns a name to the embedded browsing context created by the object when applicable. |
form |
Associates the <object> element with a <form> element. |
width |
Specifies the width of the embedded resource in CSS pixels. |
height |
Specifies the height of the embedded resource in CSS pixels. |
Example
This example uses the <object> element to display a text file from the example website. If the resource cannot be displayed, the fallback link remains available.
Usage Notes
The <object> element can embed several types of external resources, including documents, images, and other content that the browser knows how to display.
The data attribute supplies the resource URL, while the optional type attribute identifies its MIME type. Supplying the correct MIME type can help the browser determine how the resource should be handled.
Content placed inside the <object> element can serve as fallback content when the resource cannot be loaded or displayed. A fallback link to the resource is often useful so users can still access it directly.
For common webpage content, more specific elements are usually preferred when available. Use <img> for ordinary images, <video> for video, <audio> for audio, and <iframe> when embedding another HTML page is the intended purpose.
Accessibility
Make sure users can understand the purpose of an embedded resource and provide useful fallback content when the resource is not available. A direct link to the same resource can help users who cannot access the embedded version.
If the embedded content contains important information, do not make that information available only through the object. Consider providing equivalent text or another accessible alternative when appropriate.
Browser Support
Baseline: Widely available indicates a feature has been supported by core browsers for at least 30 months. At this stage, the feature is considered stable and safe for most websites to use without needing to worry about compatibility issues or fallbacks, as it is supported by the vast majority of users' devices and browser versions.
For detailed browser compatibility information, see Can I Use: HTML <object> Element .
Related Elements
The <object> element is related to the <embed> element for embedding external content, the <iframe> element for embedding another webpage, and the <param> element historically used to supply parameters to an object.
