|Contents||param elements followed by block-level elements and/or inline elements|
|Contained in||head, inline elements, block-level elements except pre|
The object element is used to include objects such as images, videos, Java applets, and VRML worlds. object is intended to replace the more specific img and applet elements, as well as the proprietary embed and bgsound elements, though a lack of browser support and severe bugs in supporting browsers make the other elements a better choice for the time being.
object's data attribute specifies the URI of the embedded object. Relative URIs are interpreted with respect to the codebase attribute if it is given.
The width and height attributes define the dimensions of the object. The value may be given in pixels or as a percentage of the parent element's width or height. Most browsers require the width and height attributes for all objects embedded using object.
The classid may be used to specify an implementation for the object. Java applets, Python applets, and ActiveX controls all provide implementations for the embedded object, and so are specified with the classid attribute, as in the following example:
classid="yahtzee.py" codetype="application/x-python" standby="Ready
to play Yahtzee?" title="My Yahtzee Game">
<object classid="java:yahtzee.class" codetype="application/java" width="400" height="250" standby="Ready to play Yahtzee?" title="My Yahtzee Game">
<object data="yahtzee.gif" type="image/gif" title="A Yahtzee animation" width="200" height="100">
Yahtzee is my <em>favorite</em> game!
This example also demonstrates the use of alternate content for browsers that cannot display the embedded object. In the example, a Yahtzee game written in Python is used if the browser supports it. A Java version is provided as an alternate for browsers that do not support Python applets. An image is given for browsers that cannot show the Java or Python applets, and plain text is used as a final alternate if images are not loaded. Note that object is backwards compatible with pre-HTML 4.0 browsers since they will ignore the <object> tags and render the innermost alternate content (the text in the example).
The preceding example also makes use of the type and codetype attributes to allow browsers to avoid requesting a file that they cannot render. The type attribute specifies the media type of the resource referenced by the data attribute while the codetype attribute specifies the media type of the classid data.
The standby attribute is also utilized in the example. This attribute provides short text to display while the object is loading.
The archive attribute can specify a space-separated list of archived files (either absolute URIs or URIs relative to the codebase), allowing the browser to download many files with a single connection and hence decreasing the total download time. The standard archive format for Java files is JAR. JAR files can be created with the jar tool included with the Java Development Kit 1.1 and up.
The declare attribute makes the object a declaration that is not immediately instantiated. This allows the object to be instantiated from a link, button, or object later in the same document. The id attribute must be used with declared objects as an identifier for the instantiating element. For example:
codetype="application/java" width="400" height="250" title="My
<img src="yahtzee.gif" alt="You get the dice!" title="Yahtzee animation" />
<p>Ready to <a href="#yahtzee">play Yahtzee</a>?</p>
The object element may contain param elements--before any other content--to provide run-time initialization data. The following example embeds a video, with an audio clip for alternate content, and includes parameters commonly understood by audio/video plug-ins. Note the placement of param elements before alternate content.
type="video/quicktime" title="Martin Luther King's "I Have
a Dream" speech" width="150" height="150">
<param name="pluginspage" value="http://quicktime.apple.com/" />
<param name="autoplay" value="true" />
<object data="mlk.wav" type="audio/x-wav" title="Martin Luther King's "I Have a Dream" speech">
<param name="autostart" value="true" />
<param name="hidden" value="true" />
<a href="mlk.html">Full text of Martin Luther King's "I Have a Dream" speech</a>
The usemap attribute can be used with object to embed a clickable image where different coordinates have different link destinations. Image maps via the img element are better supported, but object-based image maps allow a full textual alternative for browsers not loading images. The usemap attribute points to a map element whose contents define the links of the various coordinates. The map may be included within the object, in which case its contents are not rendered on image-loading browsers, or it may be given outside the object element so that its contents are rendered.
The following example gives two images, one an alternate if the first type of image is not supported. The images share a single image map definition, which is included within the object element. The map element contains a menu of links to be rendered on browsers not loading images.
usemap="#map" type="image/png" title="site map" width="300"
<object data="sitemap.gif" usemap="#map" type="image/gif" title="site map" width="300" height="200">
<li><a href="/reference/" coords="5,5,95,195">HTML and CSS reference</a></li>
<li><a href="/design/" coords="105,5,195,195">Design Guide</a></li>
<li><a href="/tools/" coords="205,5,295,195">Tools</a></li>
The tabindex attribute specifies a number between 0 and 32767 to indicate the tabbing order of the element. An object with tabindex="0" or no tabindex attribute will be visited after any elements with a positive tabindex. Among positive tabindex values, the lower number receives focus first. In the case of a tie, the element appearing first in the XHTML document takes precedence.
The align attribute, deprecated in XHTML 1.0, specifies the alignment of the object. The values top, middle, and bottom specify the object's position with respect to surrounding content on its left and right.
align="middle" aligns the center of the object with the current baseline. To center the object horizontally on the page, place the object in a centered block, e.g.,
The other align values, left and right, specify a floating object; the object is placed at the left or right margin and content flows around it. To place content below the object, use <br clear=left|right|all> or the CSS clear property on the next element as appropriate.
The border attribute, deprecated in XHTML 1.0, specifies the width of the object's border. Specifying border="0" will eliminate the border around a linked object in most browsers, though some allow the user to override this. Authors should only use border="0" if the object would be clearly recognizable as a link, or as a method of de-emphasizing a link. For example:
width="90" height="90" border="0"></object>Web Authoring
The deprecated hspace and vspace attributes allow an author to suggest horizontal gutters and vertical gutters, respectively, around the object. The value must be in pixels and applies to both sides of the object. Style sheets provide more flexibility in specifying the space around objects.
The object element is most useful as a body element and can be contained within either inline or block-level elements. The contents of object should be elements that can be contained within object's parent element. For example, an a element containing an object should not have any block-level elements as the contents of the object.