HTML <object> Tag
The <object> tag specifies an embedded object within an HTML document. It is generally used for embedding multimedia (audio, video, Java applets, Flash applications, etc.) or another HTML document into the web page.
You can include fallback content inside the <object> tag that will be displayed if the browser does not support the tag or if the resource fails to load.
You can use the <param> tag to pass parameters to plugins embedded using the <object> tag.
For images, the <img> tag is usually preferred. When using <object>, you should define at least one of the type or data attributes.
Syntax
The <object> tag comes in pairs. The content is written between opening (<object>) and closing (</object>) tags. The <object> tag is used as a child element of <body>.
The data attribute is required to specify the resource URL. The type attribute is optional but recommended to specify the MIME type for proper handling.
Example of the HTML <object> tag:
Example of HTML <object> Tag
<!DOCTYPE html>
<html>
<head>
<title>Title of the webpage</title>
</head>
<body>
<p>Embedded video with fallback content:</p>
<object width="320" height="240" data="https://www.w3docs.com/uploads/media/default/0001/01/1280x720.mp4" type="video/mp4">
<p>Your browser does not support the object tag. <a href="https://www.w3docs.com/uploads/media/default/0001/01/1280x720.mp4">Download the video</a> instead.</p>
</object>
</body>
</html>Attributes
| Attribute | Value | Description |
|---|---|---|
| align | top bottom middle left right | Specifies the alignment of the content inside the element relative to surrounding elements. Not supported in HTML5. |
| archive | URL | Defines a space-separated list of URLs to archives containing resources relevant to the object. Not supported in HTML5. |
| border | pixels | Sets the width of the border around the element. Not supported in HTML5. |
| classid | URL | Sets the URL of the object's implementation. It can be used together with, or instead of, the data attribute. Not supported in HTML5. |
| codebase | URL | Defines the path used to resolve relative URIs specified by classid, data, or archive. Defaults to the base URI of the current document. Not supported in HTML5. |
| codetype | media_type | Sets the media type of the code referred to by the classid attribute. Not supported in HTML5. |
| data | URL | Sets the URL of the resource that will be used by the object. Required. |
| declare | declare | Specifies that the object should only be declared, not instantiated. Not supported in HTML5. |
| form | form_id | Specifies one or more forms the element belongs to. |
| height | pixels | Specifies the height of the object. |
| hspace | pixels | Specifies the whitespace on the left and right sides of the object. Not supported in HTML5. |
| name | name | Specifies a name for the object. |
| standby | text | Specifies a text to be displayed while the object is loading. Not supported in HTML5. |
| tabindex | number | Sets the position of the element in the tabbing navigation order for the current document. |
| type | media_type | Specifies the media type of the data specified in the data attribute. Optional but recommended. |
| usemap | #mapname | Specifies the name of a client-side image map to be used with the object (a hash-name reference to the <map> element). |
| vspace | pixels | Sets the whitespace on top and bottom of the object. Not supported in HTML5. |
| width | pixels | Sets the width of the object. |
The <object> tag also supports the Global attributes and the Event Attributes.
Note: Attributes like align, border, hspace, and vspace are obsolete. Use CSS for layout and styling in modern development.
Practice
Which of the following attributes can be used with the HTML <object> tag?