HTML introduces various functional tags for different uses. Some are more important, and some are less, based on the need of the content. The HTML
<embed> tag is one of them, and it's easy to understand the intent of its function in an HTML document. This tutorial will teach you about HTML embed tags and their proper usage.
What Is HTML <embed> Tag?
<embed> tag in HTML is used to embed external resources, such as videos, games, or audio files, into an HTML document. It is an empty tag, meaning it does not have a closing tag and can't contain any content.
Here is an example of how to use the
<embed> tag to embed a video file:
<!-- HTML code for a webpage with an embedded video --> <html> <head> <title>My Video</title> </head> <body> <h1>My Video</h1> <embed src="video.mp4" type="video/mp4" /> </body> </html>
In the above example, The
src attribute specifies the URL of the resource to be embedded, and the
type attribute specifies the MIME type of the resource. In this example, we specify that the resource is a video in MP4 format.
<embed> tag can also embed other types of resources, such as audio files, Flash animations, PDFs, etc.
<!-- Embed an audio file --> <embed src="audiofile.mp3" type="audio/mpeg"> <!-- Embed a Flash game --> <embed src="game.swf" type="application/x-shockwave-flash"> <!-- Embed a PDF --> <embed src="document.pdf" type="application/pdf" width="800" height="600" />
In addition to the
src and type attributes, the
<embed> tag also supports a number of other attributes that can be used to customize the appearance and behavior of the embedded resource. For example, the
height attributes can specify the dimensions of the embedded resource, or the
autoplay attribute can be used to play the resource on page load automatically.
Here is an example of how to use some of these additional attributes:
<!-- Embed a video with custom dimensions and autoplay --> <embed src="myvideo.mp4" type="video/mp4" width="640" height="360" autoplay>
Not all browsers support the
<embed> tag, so alternative methods can be used to embed external resources in HTML documents. For example, the
<iframe> tag can be used to embed external web pages, or the
<audio> tags can be used to embed multimedia files.