html
  1. html-object-tag

HTML <object> Tag

  • The HTML <object> tag is used to embed another HTML document within the current HTML document.
  • It is commonly used to display multimedia content such as videos, audios, and images.
  • The <object> tag is an alternative to the <iframe> tag, which can also be used to embed content within an HTML document.

Syntax

The syntax for the HTML <object> tag is as follows:

<object data="URL">...</object>

Here, the required data attribute specifies the URL of the document to be embedded.

Example

Here's an example of how to use the HTML <object> tag to embed a PDF document within an HTML page:

<object data="example.pdf" type="application/pdf" width="100%" height="650px">
  <p>Your browser does not support PDFs. Please download the PDF to view it: <a href="example.pdf">Download PDF</a>.</p>
</object>
Try Playground

The output of the above code will be a PDF document embedded within the HTML page with a fallback option in case the browser does not support PDFs.

Explanation

  • The data attribute specifies the URL of the PDF document to be embedded.
  • The type attribute specifies the MIME type of the embedded document.
  • The width and height attributes specify the size of the embedded document within the HTML page.
  • If the browser does not support the embedded document, the content inside the <object> tag will be displayed as a fallback option.

Use

The HTML <object> tag can be used to embed various multimedia content within an HTML document such as videos, audios, SVG images or any type of documents like MS Word, PDF, Excel and more.

Important Points

  • The <object> tag should be used with caution when embedding external content as it may cause security and compatibility issues.
  • The URL provided in the data attribute must be a valid and accessible URL.

Summary

The HTML <object> tag is useful for embedding various multimedia content within an HTML document. It provides a fallback option in case the browser does not support the embedded content. However, it should be used with caution when embedding external content and the URL provided in the data attribute must be valid and accessible.

Published on: