Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > HTML Tags > HTML object tag

Bypass main content

HTML object tag

Note: If you don't know what an element/tag is and/or how you must use it we recommend you to read our HTML tags and attributes tutorial that you can find in our HTML tutorials section.

Bypass main content

Description

The HTML object element is used to run external aplications like applets, flash movies or images.

This element becomes useful when showing content that's not natively supported by the browser, by allowing authors to specify which application should intervene in order to show properly the custom content.

Since the beginning, this element has been very poorly supported by browsers, and even nowadays, only some instances are compatible. This is the case of flash movies, that need to be defined using the attributes "data" and "type" (instead of "classid") to work in browsers like Netscape and Mozilla.

Some attributes for this element have a strong presentational nature, for which they have been deprecated in HTML 4.01 in favor of style sheets. These attributes are: "align", "border", "hspace" and "vspace".

Examples

In the next example, the HTML object element is used to show an image.

Code
<object data="/img/p/link-to-us/button.jpg" type="image/jpeg" width="88" height="31"></object>
View

Next, a flash movie is inserted using the HTML object element. Note that the declaration uses the "data" and "type" attributes instead of the typical "classid". This is because movies inserted using the "classid" attribute aren't displayed in some browsers like Mozilla and Netscape. In fact, the following, is the most compatible "valid" declaration until now. The only problem with it is that in Internet Explorer, the movie is fully loaded before starting, which could be a problem for long movies.

Code
<object data="/img/button.swf" type="application/x-shockwave-flash" width="88" height="31">
<param movie="/img/button.swf" />
</object>
View

Attributes

id (name)

The "id" attribute assigns an identifier to the associated element. This identifier must be unique in the document and can be used to refer to that element in other instances (e.g., from client-side scripts).

<p id="paragraph1">This is the first paragraph, named "paragraph1". To dynamically change its properties use this identifier.</p>

class (cdata)

The "class" attribute assigns a class name (or a list of class names separated by spaces) to the container element. It's used together with style sheets and tells the browser the class (or classes) to which the element is associated with.

A class gives presentational attributes to elements (read more at the Cascading Style Sheets tutorial).

<p class="references">This article is based on the book "Wind in the trees" by Jhon L. Brooks</p>
<p class="references important">This article is based on the book "Wind in the trees" by Jhon L. Brooks... and is more important than the one before.</p>

style (style)

This attribute is used to define presentational attributes for the containing element, and its value should be composed by style sheets properties. Although, in some cases, it can become useful, a better practice is to place presentational attributes in external files, relating them to elements with the "class" attribute. This way you keep the semantic and presentational parts of your document separated.

You can find more information about presentational attributes at the Cascading Style Sheets tutorial.

<p style="color: #0000FF; font-size: 12pt">This is a paragraph with a defined style.</p>
<p>And this is another text without style.</p>

title (text)

The purpose of this attribute is to provide a title for the element. Its value must be a short and accurate description of the element. Browsers usually render it as a "tool tip" when the user puts the mouse pointer over the element for a small period of time.

Code
<a title="HTMLQuick.com" href="http://www.htmlquick.com">HTML code</a>
View

lang (langcode)

Specifies the language of an element's content. The default value in "unknown".

When writing XHTML 1.0 documents, the attribute used to specify the language of an elements is "xml:lang". For forward and backward compatibility both attributes can be used simultaneously like in the example below. Note, that in XHTML 1.1 the "lang" attribute has been completely replaced by "xml:lang" and its use is no longer valid.

<p lang="en" xml:lang="en">This is a paragraph in english.</p>
<p lang="es" xml:lang="es">Este es un párrafo en español.</p>

dir

This attribute indicates the direction in which the texts of the element must be read. This includes content, attribute values and tables. It has two possible values that are case-insensitive:

  • RTL: Right to left.
  • LTR: Left to right.
<q lang="he" dir="rtl">...an Hebrew quotation...</q>

name (cdata)

This attribute assigns a name to the element, that can be used to refer to it in scripts or style sheets.

<object name="photo1" data="img/photo1.png" type="image/png"></object>

usemap (uri)

The value of this attribute points to an image map (HTML map element) that will be associated to this element. Therefore, this value must match the value of the "name" attribute in the image map.

<map name="mainmenu">
...Map info...
</map>
<img src="../img/mainmenu.png" alt="Main menu" usemap="mainmenu" />

tabindex (number)

Specifies the position of this element in the tabbing order. The tabbing order defines a sequence with all the elements than can receive the focus. Users can navigate this sequence via keyboard (usually with the "tab" key).

<a href="doc1.html" tabindex="1">First document in the list</a>
<a href="doc2.html" tabindex="2">Second document in the list</a>
<a href="doc3.html" tabindex="3">Third document in the list</a>

width (length)

Specifies the width of the image. This can be different to the real width of the image, and browsers should resize it as needed. However, specifiyng a different width may cause a pixelated images (when bigger) or longer load periods (when smaller).

<img src="img/treasure-map.jpg" width="100" />

height (length)

Specifies the height of the image. This can be different to the real height of the image, and browsers should resize it as needed. However, specifiyng a different height may cause a pixelated images (when bigger) or longer load periods (when smaller).

<img src="img/treasure-map.jpg" height="50" />

classid (uri)

This attribute points to the location of an object's implementation. May be replaced or used with the "data" attribute, depending on the object's type.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0">
...Object data...
</object>

codebase (uri)

Sets the base URI used as starting point to resolve relative URIs in the "classid", "data" and "archive" attributes. The default value is the base URI of the document.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0">
...Object data...
</object>

codetype (content-type)

Specifies the content type of the object declared in the "classid" attribute. When absent, it takes the value of the "type" attribute.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" codetype="application/x-shockwave-flash">
...Object data...
</object>

data (uri)

Specifies the location of the object's data.

<object data="img/picture.jpg"></object>

type (content-type)

Specifies the content type of the data declared in the "data" attribute.

<object data="img/picture.jpg" type="image/jpg"></object>

archive (uri)

Provides a space-separated list of resources useful for the object, that may include the resources declared in the "classid" and "data" attributes. It can be used to preload resources, reducing the loading time.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" archive="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
...Object data...
</object>

declare

The presence of this boolean attribute means that the current object is meant to work as a declaration only. To be used, the object must be instantiated by another object referring to it.

Remember that in XHTML, boolean attributes must take their own names as value (e.g., attr_name="attr_name").

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" declare="declare">
...Object data...
</object>

standby (text)

Provides a text to be shown while the object is loading.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" standby="Object loading. Please wait...">
...Object data...
</object>

align

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

This attribute specifies the position of the image with respect to the surrounding content. It can take the following case-insentive values:

  • top: The top side of the image is vertically aligned with the baseline.
  • middle: The image is vertically centered with respect to the baseline.
  • bottom: The bottom side of the image is vertically aligned with the baseline. This is the default value.
  • left: The image is floated to the left margin.
  • right: the image is floated to the right margin.
<img src="img/picture.png" align="center" />

border (pixels)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

This attribute sets the border width in number of pixels.

<img src="img/picture.png" border="2" />

hspace (pixels)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

Sets the amount of white space (in pixels) to be inserted at the left and right margins of the image.

<img src="img/picture.png" hspace="20" />

vspace (pixels)

This attribute has been deprecated in HTML 4.01. Therefore its use is no longer recommended.

Sets the amount of white space (in pixels) to be inserted at the top and bottom margins of the image.

<img src="img/picture.png" vspace="10" />

Events

  • onclick
  • ondblclick
  • onmousedown
  • onmouseup
  • onmouseover
  • onmousemove
  • onmouseout
  • onkeypress
  • onkeydown
  • onkeyup

See a complete list and information about events in HTML

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate