Updated June 23, 2023
Introduction to HTML object Tag
The HTML <object> tag for external resources specifies a container. Multimedia content such as audio, videos, images, PDFs, and Flash files are utilized in web pages by incorporating external resources. 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 the HTML <object> tag can be written as follows:
<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 the object will use.
- 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?
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
Examples are as follows.
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:
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 400px height and 200px width. The hexadecimal #8FBC8F represents the background color for the HTML page body.
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:
Explanation: In the above example, we have embedded the video by using the HTML object tag with the help of height and width attributes which sets the video in the proper place. Embed the video url from YouTube and paste into 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:
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 the 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:
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 8 pixels.
Conclusion
So far, we have studied HTML object tags that can remain within Inline elements and block-level elements except for pre. In most instances, an HTML object inserts content assisted by browser plug-ins.
Recommended Articles
This is a guide to HTML object Tag. Here we discuss an introduction to HTML object Tag, syntax, and how it works with programming examples. You can also go through our other related articles to learn more –