Skip to: content, navigation

by Ian Lloyd

object (HTML element)

Spec
Depr. Empty Version
No No HTML 4
Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Partial Partial Partial Partial

Example

In this example, a super-simple object element is used to display an image:

<object data="giant-dog.jpg">
</object>
Type
inline element
Contains
param, followed by block-level elements, inline elements
Contained by
block-level elements, inline elements (except pre)

Description

The object element’s purpose is to embed into a document a variety of different kinds of media files. Historically, it was used primarily for placing ActiveX controls onto a page, but it can also be used to embed images (.gif, .jpg, and so on), movie files and applets, video files, PDF documents, Flash, and even HTML.

While this element is specified in the HTML 4 recommendation, and thus constitutes valid markup, it’s often shunned in favor of the better supported, but nonstandard embed element.

To embed Flash using object, rather than going down the nonstandard embed route, use the following markup:

<object data="movie.swf"
    type="application/x-shockwave-flash"
    width="200" height="100">
  <param name="movie" value="movie.swf">
  <param name="wmode" value="opaque">
</object>

The param element with the name of "movie" helps Internet Explorer to load the Flash file. The "wmode" encourages IE to play nicely with the z-index property, allowing other elements to be placed on top of the Flash movie.

Use This For …

This element is used for media files, applets, and ActiveX objects. For images, it’s currently better practice to use the completely supported img element, rather than take a risk using object; img is also far less clunky to use.

Compatibility

IE5.5Partial
6.0Partial
7.0Partial
Firefox1.0Partial
1.5Partial
2.0Partial
Safari1.3Partial
2.0Partial
3.0Partial
Opera9.2Partial
9.5Partial

This element is not completely supported, although it has to be said that the support that is available very much depends on the type of object that’s being embedded. Internet Explorer displays simple images poorly, with horizontal and vertical scrollbars, but is able to display an embedded Word document, albeit with a warning in the form of an ActiveX alert. Safari and Firefox, on the other hand, behaves impeccably with images, yet no amount of coaxing or installing of third-party plugins will allow the Word document to display—even with Microsoft Office installed on the host machine. For this reason, before you apply it, you should consider the purpose for which you need to use the object element. If it’s to display images, you’ll likely be better off to use the img element.

In this Section

Related Reading

User-contributed notes

ID:
#4
Date:
Fri, 28 Mar 2008 12:28:58 GMT
Contributed by:
AutisticCuckoo

This section completely missed the point of the OBJECT element type, which is that it allows authors to provide a rich equivalent if the external object isn't supported. Compared with the measly ALT attribute of an image, there's a world of difference.

<h1>How to Make Coffee</h1>
<object type="video/mpeg" data="coffee.mpg">
<object type="image/png" data="coffee.png">
<ol>
<li>Fill the coffee kettle with water.</li>
<li>Heat the water until it starts boiling.</li>
<li>Add the ground coffee beans.</li>
<li>Let the brew simmer for a few moments.</li>
</ol>
</object>
</object>

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters