Introduction to HTML object Tag

HTML object Tag

Introduction to HTML object Tag

The HTML <object> tag for external resource specifies a container. The external resource will be used to demonstrate multimedia in web pages such as audios, videos, images, PDFs, and Flash. This can be used to show another web page inside the HTML page. Along with this tag, the <param> tag is also used to describe different parameters. Compared to the tags <video> and <audio>, the HTML object tag allows multimedia files to be inserted into the web page. The <object> tag is much more commonly used for embedding resources than the <embed> tag, owing to compatibility issues. This tag is often widely known as the element <object>.

Syntax

The syntax for HTML object tag can be written as shown below:

<object data= ”url ” type= ”content type ”>
. . . . .
</object>

For instance,

<object height= "200" width= "400" data= "url"> </object>

It displays the object with the specified height and width attributes.

Parameters

The parameters of the object tag are:

  • data: It stipulates the resource URL which will be used by the object.
  • type: It specifies the type of content of the resource the data describes.
  • form: It indicates the element of the form to which the object element is related.
  • height: It provides the height of the object.
  • width: It provides the height of the object.
  • name: It provides the name of the object.
  • the type must match: It states clearly that if the type attribute meets the appropriate text type of resources provided on the data attribute, the resource should be inserted.

How does HTML object Tag work?

The element could be used to incorporate an included component, the data to present and also for additional values that the object needs at compile time. We can combine object elements and using this possibility, we can define multiple objects for one browser each. While all major browsers do not support the object element, the use of the element is minimal.

Examples to Implement HTML object Tag

Below are the examples mentioned :

Example #1

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> HTML Object Tag Example </title>
<style>
body {
background-color: #8FBC8F;
}
</style>
</head>
<body>
<center>
<h2> HTML Object Tag</h2> <br>
<object data= "https://www.shareasale.com/images/edu-logo.jpg" width="400px" height="200px"></object>
</center>
</body>
</html>

Output:

object element

Explanation: In the above example, we have created the object tag in the center of the web page with <center> tag. The object element has displayed with the 400px height and 200px width. The hexadecimal #8FBC8F represents background color for the HTML page body. Popular Course in this categoryHTML Training (12 Courses, 19+ Projects, 4 Quizzes)12 Online Courses | 19 Hands-on Projects | 89+ Hours | Verifiable Certificate of Completion | Lifetime Access | | 4 Quizzes with Solutions
4.5 (6,492 ratings)Course Price
₹6999 ₹41999
View Course


Related CoursesBootstrap Training (2 Courses, 6+ Projects)XML Training (5 Courses, 6+ Projects)CSS Training (9 Courses, 9+ Projects)

Example #2

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> HTML Object Tag Example </title>
<style>
body{
background-color: #8FBC8F;
}
</style>
</head>
<body>
<center>
<h2> HTML Object Tag</h2> <br>
<object height="200px" width="400px" data="https://www.youtube.com/embed/Xs3MCM0dXW0"></object>
</center>
</body>
</html>

Output:

HTML object Tag2

Explanation: In the above example, we have embedded the video by using the HTML object tag with help of height and width attributes which sets the video in the proper place. Embed the video url from the YouTube and paste in the data attribute.

Example #3

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> HTML Object Tag Example </title>
<style>
body{
background-color: #8FBC8F;
}
</style>
</head>
<body>
<center>
<h2> HTML Object Tag</h2> <br>
<object data= "https://www.shareasale.com/images/edu-logo.jpg" width="400px" height="200px" vspace="150"></object>
</center>
</body>
</html>

Output:

HTML object Tag3

Explanation: In the above example, we have used the object tag to display the image on the web page. The object tag uses vspace attribute to define the whitespace on top and bottom of an object element. Here, we are setting the margin on top and bottom with 150 pixels.

Example #4

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> HTML Object Tag Example </title>
<style>
body{
background-color: #8FBC8F;
}
</style>
</head>
<body>
<center>
<h2> HTML Object Tag</h2> <br>
<object data= "https://www.shareasale.com/images/edu-logo.jpg" width="400px" height="200px" border="8"></object>
</center>
</body>
</html>

Output:

display the border

Explanation: In the above example, we have used the border attribute to display the border for the object element. The border attribute specifies the width of the border in the pixels. Here, we are representing the border width with the 8 pixels.

Conclusion

So far, we have studied about HTML object tag that can remain within Inline elements, block-level elements except for pre. In the majority of instances, an HTML object is used to insert content assisted by browser plug-ins. When defining data, it is preferred to use the type attribute, as it helps the user to avoid loading information for types of unsupported content.

Recommended Articles

This is a guide to HTML object Tag. Here we discuss an introduction to HTML object Tag, syntax, how does it work with programming examples. You can also go through our other related articles to learn more –

  1. DOCTYPE HTML
  2. HTML Article Tag
  3. HTML Form Action
  4. Nested Table in HTML

Leave a Comment

Your email address will not be published. Required fields are marked *