<object>

The HTML <object> element inserts external content like multimedia or interactive elements into a webpage and can display fallback content if the resource fails to load.

object tag

The HTML <object> element represents an external resource that can be displayed as an image, a nested browsing context, or a resource handled by a plugin.

Syntax

index.html
<object data="resource" type="MIME-type" width="width" height="height">
  Alternative content for unsupported cases.
</object>

object Demo

The object element
index.html
<h1>The object element</h1>
<object data="movie.mp4" type="video/mp4" width="640" height="360"></object>

An embedded image

index.html
<object data="pic_trulli.jpg" width="300" height="200"></object>

An embedded HTML page

index.html
<object data="snippet.html" width="500" height="200"></object>

Explanation and Purpose

The <object> tag is used to embed external resources within a webpage, such as web pages, images, media players, or plug-in applications.

  • For images, the <img> tag is more suitable.
  • For embedding HTML content, the <iframe> tag is recommended.
  • For multimedia files like videos and audio, the <video> and <audio> tags are preferred.

Embedded Components

The <object> tag was initially created to integrate additional functionality within web browsers through external components. These components, often referred to as extensions or add-ons, enhanced browser capabilities in various ways, such as:

  • Running Java-based applications
  • Executing ActiveX controls
  • Playing Flash animations
  • Displaying interactive maps
  • Performing security scans
  • Authenticating banking credentials
  • Most modern browsers no longer support Java-based applications or external plug-ins.
  • ActiveX controls have been completely phased out across all browsers.
  • Support for Shockwave Flash has been discontinued in the latest browser versions.

Attributes

AttributeValueDescription
dataURLDefines the URL of the resource to be used by the object.
formform_idIndicates the form to which the object belongs.
heightpixelsSpecifies the object's height.
namenameAssigns a name to the object.
typemedia_typeDeclares the media type of the resource mentioned in the data attribute.
typemustmatchtrue/falseDetermines if the type attribute must match the actual resource content for it to be displayed.
usemap#mapnameSets the name of a client-side image map associated with the object.
widthpixelsDefines the object's width.

Default CSS Settings

By default, most web browsers render the <object> element using the following predefined styles:

style.css
object:focus {
  outline: none;
}

See also

Conclusion

The <object> tag in HTML is used to embed external resources such as images, videos, or interactive content within a webpage. It allows specifying attributes like width and height for its size. While it was once used to integrate plugins like Flash or Java applets, most modern browsers no longer support these plugins. Today, tags like <video>, <audio>, and <iframe> are preferred for embedding media and content.