Skip to content

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

html
<!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

AttributeValueDescription
aligntop bottom middle left rightSpecifies the alignment of the content inside the element relative to surrounding elements. Not supported in HTML5.
archiveURLDefines a space-separated list of URLs to archives containing resources relevant to the object. Not supported in HTML5.
borderpixelsSets the width of the border around the element. Not supported in HTML5.
classidURLSets the URL of the object's implementation. It can be used together with, or instead of, the data attribute. Not supported in HTML5.
codebaseURLDefines 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.
codetypemedia_typeSets the media type of the code referred to by the classid attribute. Not supported in HTML5.
dataURLSets the URL of the resource that will be used by the object. Required.
declaredeclareSpecifies that the object should only be declared, not instantiated. Not supported in HTML5.
formform_idSpecifies one or more forms the element belongs to.
heightpixelsSpecifies the height of the object.
hspacepixelsSpecifies the whitespace on the left and right sides of the object. Not supported in HTML5.
namenameSpecifies a name for the object.
standbytextSpecifies a text to be displayed while the object is loading. Not supported in HTML5.
tabindexnumberSets the position of the element in the tabbing navigation order for the current document.
typemedia_typeSpecifies the media type of the data specified in the data attribute. Optional but recommended.
usemap#mapnameSpecifies the name of a client-side image map to be used with the object (a hash-name reference to the <map> element).
vspacepixelsSets the whitespace on top and bottom of the object. Not supported in HTML5.
widthpixelsSets 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?

Dual-run preview — compare with live Symfony routes.