HTML <embed> Tag

The HTML <embed>  tag is used to embed external content such as multimedia files (videos, audio, and images), interactive applications, or other web content into an HTML document. This tag allows developers to seamlessly integrate external resources into their webpages, making it an essential tool for embedding media from sources like PDF files, Flash content, or even web applications. The <embed>  tag is a self-closing tag, and it is widely supported across modern browsers, making it a versatile solution for displaying different types of content.

Syntax of the <embed>  Tag

html
<embed src="URL" type="MIME-type" width="value" height="value">
  • src: Specifies the URL of the external file or resource to be embedded.
  • type: Specifies the media type or MIME type of the embedded resource (e.g., application/pdf for PDF files or video/mp4 for MP4 videos).
  • width: Specifies the width of the embedded content.
  • height: Specifies the height of the embedded content.

Attributes of the <embed>  Tag

The <embed>  tag supports several attributes that help customize the display and functionality of the embedded content:

AttributeDescription
srcSpecifies the URL of the external content or file to embed.
typeDefines the MIME type of the embedded resource (e.g., application/pdf, video/mp4).
widthDefines the width of the embedded content in pixels.
heightDefines the height of the embedded content in pixels.
autoplaySpecifies whether the media (like audio or video) should automatically start playing when the page loads.
loopSpecifies whether the media should loop continuously.
allowscriptaccessControls whether or not the embedded content has access to execute JavaScript.
allowfullscreenAllows the embedded media to be displayed in fullscreen mode.

The src and type attributes are essential for embedding content, while other attributes like width, height, autoplay, and loop can enhance the presentation and behavior of the media.

Examples of HTML <embed> Tag

Example 1: Embedding a PDF File

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Embed PDF Example</title>
</head>
<body>
    <h1>Embedded PDF Document</h1>
    <embed src="https://example.com/sample.pdf" type="application/pdf" width="600" height="400">
</body>
</html>

In this example, a PDF file is embedded into the webpage. The embed tag sets the src to the PDF file's URL and specifies the type as application/pdf to ensure proper rendering.

Example 2: Embedding an MP4 Video

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Embed MP4 Video</title>
</head>
<body>
    <h1>Embedded Video</h1>
    <embed src="https://example.com/sample-video.mp4" type="video/mp4" width="640" height="360" autoplay loop>
</body>
</html>

Here, an MP4 video is embedded into the webpage using the <embed>  tag. The autoplay and loop attributes are used to automatically play the video and loop it continuously.

FAQs About HTML <embed> Tag

Q1: What is the purpose of the HTML <embed>  tag?
A: The <embed>  tag is used to embed external content, such as videos, audio, PDFs, and other multimedia files, into an HTML document.

Q2: What types of content can be embedded using the <embed>  tag?
A: The <embed>  tag can be used to embed various types of content, including videos, audio, PDFs, interactive applications, Flash content, and web applications.

Q3: Can the <embed>  tag be used for responsive content?
A: Yes, by setting the width and height attributes in percentages or using CSS media queries, you can make the embedded content responsive for different screen sizes.

Q4: Is the <embed>  tag supported in all browsers?
A: Yes, the <embed>  tag is supported by all major browsers, including Chrome, Firefox, Safari, and Edge. However, Flash-based content may not be supported as Flash is being phased out.

Q5: What is the difference between the <embed>  and <iframe> tags?
A: The <embed>  tag is typically used for embedding media and external content, while the <iframe> tag is often used to embed entire webpages or web applications within a page.

tools

HTML

Related Articles