embed (HTML element)

Share this article

Description

embed is a non-standard but well-supported element that’s used to embed multimedia content, including media types that mightn’t usually be natively supported by the browser. It can also be used for embedding media types that are supported, such as images in .jpg, .gif, or .png format. embed isn’t part of any currently recognized standard, so if you use it, your page can’t possibly validate; to create valid markup, you’ll need to use the object element, which was defined in HTML 4. That said, using embed is widely recognised as a good way to embed Flash in an accessible manner, and many believe that it’s acceptable to compromise validity for the sake of accessibility. embed
won’t work for formats that are natively supported in the browser, such as HTML and images — use the built-in, properly supported mechanisms for such formats. The formats that embed supports are generally restricted to those that would require an additional plugin in order to work. Although embed is an empty element, an end tag is still required for the sake of browser compatibility.

Example

In this example, a super-simple embed element is used to display a video file in .mp4 format:

<embed src="volksworld-video-report.mp4">
</embed>

Use This for…

This element is used for media files (primarily movie files, such as Flash and QuickTime video).

In this Section

Frequently Asked Questions about Embedding HTML Elements

What is the purpose of the HTML embed tag?

The HTML embed tag is a powerful tool that allows you to incorporate external content into your web page. This could be anything from a video or audio file, to an interactive game or application. The tag is versatile and supports a wide range of media types, making it a valuable tool for enhancing the interactivity and richness of your web content.

How do I use the HTML embed tag?

Using the HTML embed tag is straightforward. You simply need to include the tag within your HTML code, and specify the source of the content you wish to embed using the ‘src’ attribute. For example, to embed a video, your code might look something like this: <embed src="myvideo.mp4">. You can also specify the dimensions of the embedded content using the ‘width’ and ‘height’ attributes.

Can I embed content from any source?

While the HTML embed tag is very flexible, it’s important to note that not all content can be embedded. The content must be publicly accessible and the provider must allow embedding. Some websites may restrict embedding to protect their content, so always ensure you have the necessary permissions before embedding content.

Are there any alternatives to the HTML embed tag?

Yes, there are several alternatives to the HTML embed tag. The ‘object’ tag is one such alternative, which offers more flexibility and control over the embedded content. Another alternative is the ‘iframe’ tag, which allows you to embed another HTML document within your current document.

What are the limitations of the HTML embed tag?

While the HTML embed tag is a powerful tool, it does have some limitations. For example, it is not supported by all browsers, so some users may not be able to view your embedded content. Additionally, the tag does not provide any fallback content in case the embedded content cannot be displayed.

How can I ensure my embedded content is accessible?

To ensure your embedded content is accessible, you can use the ‘alt’ attribute to provide a text description of the content. This description will be displayed if the content cannot be loaded, and can also be read by screen readers to assist visually impaired users.

Can I control the appearance of the embedded content?

Yes, you can control the appearance of the embedded content using CSS. This allows you to adjust the size, position, and other visual aspects of the content to fit your web page’s design.

Can I embed content from social media platforms?

Yes, many social media platforms provide options for embedding content. For example, you can embed tweets from Twitter, posts from Facebook, or videos from YouTube. However, the process for embedding this content may vary between platforms, so it’s best to refer to the platform’s specific instructions.

Can I embed interactive content?

Yes, the HTML embed tag supports a wide range of media types, including interactive content. This could be an interactive map, a game, or an application. However, keep in mind that the user’s browser must support the specific media type in order for the content to be displayed.

How can I troubleshoot issues with the HTML embed tag?

If you’re having trouble with the HTML embed tag, there are a few things you can check. First, ensure that the ‘src’ attribute is correctly pointing to the content you wish to embed. Also, check that the content is publicly accessible and that embedding is allowed. If you’re still having trouble, it may be a browser compatibility issue, so try viewing your web page in a different browser.

Adam RobertsAdam Roberts
View Author

Adam is SitePoint's head of newsletters, who mainly writes Versioning, a daily newsletter covering everything new and interesting in the world of web development. He has a beard and will talk to you about beer and Star Wars, if you let him.

Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week
Loading form