HTML <embed>
Tag
The <embed>
tag in HTML allows you to embed external resources, such as plugins, interactive content, and other applications, directly into your web page. It's commonly used to display content that cannot be directly rendered by the browser itself, requiring an external viewer or plugin to handle the content. This includes things like PDFs, Flash animations (though now less common), and other media types.
Syntax
<embed src="url" type="mime_type" width="pixels" height="pixels" attribute1="value1" attribute2="value2">
Attributes
Attribute | Value | Description |
---|---|---|
src |
URL | Specifies the URL of the external resource to embed. |
type |
MIME Type | Specifies the MIME type of the embedded resource, helping the browser select the correct plugin or application for rendering. |
width |
Pixels | Specifies the width of the embedded content area, typically in pixels. |
height |
Pixels | Specifies the height of the embedded content area, typically in pixels. |
alt |
text | Specifies an alternate text for the embedded content, useful for accessibility. |
name |
text | Defines a name for the embed element (used for scripting). |
Any specific attribute for the plugin | Specific to plugin | Some plugins might have additional custom attributes to pass on configuration values. |
Example
<embed src="document.pdf" type="application/pdf" width="600" height="400" alt="Embedded PDF Document">
More Examples
Embedding a PDF Document
This example demonstrates embedding a PDF document into your webpage. The type
attribute is set to application/pdf
, which helps the browser to select the appropriate PDF viewer plugin if available.
<embed src="sample.pdf" type="application/pdf" width="800" height="600" alt="Sample PDF">
Embedding Flash Content (Less Common)
Although Flash is no longer widely supported, this example shows how it was used with the <embed>
tag.
<embed src="animation.swf" type="application/x-shockwave-flash" width="550" height="400" alt="Flash Animation">
Embedding an SVG image
This example shows how to embed an SVG image directly into the page using the tag.
<embed src="myimage.svg" type="image/svg+xml" width="300" height="200" alt="SVG Image">
Using Additional Attributes
Some plugins require custom attributes. While there is no standard, you can include additional attributes depending on the needs of the plugin you're using:
<embed src="my_custom_app.app" type="application/x-custom-app" width="400" height="300" parameter1="value1" parameter2="value2" alt="Custom Application">
Browser Support
Browser | Support |
---|---|
Chrome | Yes |
Edge | Yes |
Firefox | Yes |
Safari | Yes |
Opera | Yes |
IE | Yes (but may require additional plugins for some content types) |
Notes and Tips
- MIME Type: Setting the correct MIME type is crucial for the browser to render the content correctly.
- Accessibility: Use the
alt
attribute to provide alternative text for the embedded content. - Plugin Availability: Ensure the user has the necessary plugins installed to view the embedded content.
- Security: Be cautious when embedding external content from untrusted sources, as it can potentially pose security risks.
- Alternatives: Consider using the
<iframe>
tag as an alternative for some types of external content, especially for embedding other web pages. The<object>
tag can also be used as alternative. - Responsiveness: Use CSS to make the embedded content responsive to different screen sizes. Setting width and height to percentage or using max-width is recommended.
- Flash Support: Remember that Adobe Flash is now end of life. Flash based embed is discouraged in modern web development.
- Modern Alternatives: For video and audio, using the HTML5
<video>
and<audio>
tags is recommended over embedding plugins.