HTML <object>

Rumman Ansari   Software Engineer   2023-03-23   496 Share
☰ Table of Contents

Table of Content:


The HTML <object> tag is used to embed external resources, such as images, videos, Java applets, and PDF documents, into an HTML document. It can also be used to embed other web-based content, such as Flash animations or interactive games.

The <object> tag has a number of attributes that can be used to customize the way the embedded content is displayed and interacted with. Some of the most commonly used attributes include:

  • data: The URL of the external resource to be embedded.
  • type: The MIME type of the embedded resource.
  • width and height: The dimensions of the embedded content.
  • alt: Alternative text to be displayed if the embedded content cannot be displayed.

Here is an example of using the <object> tag to embed an image:


<object data="image.jpg" type="image/jpeg" width="400" height="300" alt="A beautiful sunset">
  <p>Sorry, your browser does not support the object tag.</p>
</object>

In this example, the <object> tag will embed the image image.jpg into the HTML document, with dimensions of 400x300 pixels. If the image cannot be displayed, the text "Sorry, your browser does not support the object tag." will be displayed instead.

It is important to note that the <object> tag may not be supported by all browsers, so it is a good idea to include fallback content within the <object> tag in case the embedded content cannot be displayed.