1. html
  2. /tags
  3. /embed

<embed>

Definition

The HTML <embed> element is used to embed external content, typically multimedia content such as videos or audio, into an HTML document. It allows you to specify the source of the external content and also provides a fallback option in case the content cannot be displayed. The <embed> element is often used in conjunction with other HTML elements to enhance the user experience, such as with the use of the <video> element to display a video player.

Examples

Here is an example of using the <embed> element to embed a YouTube video into an HTML document:

<embed src="https://www.youtube.com/embed/dQw4w9WgXcQ" type="video/mp4" width="640" height="480">

In this example, the <src> attribute specifies the source URL of the YouTube video, and the <type> attribute specifies the MIME type of the content. The '<width>and<height>attributes specify the dimensions of the embedded content. Note that the<embed>` element can also be used to embed other types of content, such as audio files.

Attributes

This element's attributes include the global attributes.

AttributeDescriptionDeprecated?
srcSpecifies the URL of the external content to be embeddedNo
typeSpecifies the MIME type of the content to be embeddedNo
widthSpecifies the width of the embedded content, in pixels or as a percentageNo
heightSpecifies the height of the embedded content, in pixels or as a percentageNo

Best Practices

  • Use the `<type> attribute to specify the correct MIME type of the content being embedded. This can help ensure that the content is displayed correctly across different browsers and devices.
  • Always provide a fallback option in case the content cannot be displayed. This can be done by using alternative content within the <embed> element or by using other HTML elements such as <object> or <iframe>.
  • Use the <width> and <height> attributes to specify the dimensions of the embedded content. This can help ensure that the content is displayed at an appropriate size for the user's device.
  • Avoid using <autoplay> and <loop> attributes indiscriminately, as these can be disruptive to the user experience. Consider whether the content actually benefits from these features and use them judiciously.
  • Use the <allowfullscreen> attribute only if it is necessary for the user to view the embedded content in fullscreen mode. This can help prevent unexpected behavior and improve the accessibility of the content.
  • Consider the accessibility implications of using the <embed> element. Provide alternative text descriptions for non-textual content, and ensure that any associated captions or transcripts are available for users who may require them.
  • Test the embedded content across different browsers and devices to ensure that it is displayed correctly and that any associated features such as playback controls or captions are functional.

Accessibility Considerations

  • Provide alternative text descriptions for non-textual content. This can be done by using the <alt> attribute on any images or videos that are embedded using the <embed> element. The alternative text should describe the content of the embedded object, so that users who are unable to see or hear it can still understand its meaning.
  • Ensure that any associated captions or transcripts are available for users who may require them. This can be especially important for video content, where captions can help make the content accessible to users who are deaf or hard of hearing.
  • Use the <allowfullscreen> attribute only if it is necessary for the user to view the embedded content in fullscreen mode. Allowing fullscreen mode can be disruptive for users who rely on assistive technology such as screen readers or magnification software.
  • Consider the impact of autoplay and looping on users who may have cognitive or neurological disabilities, such as autism or ADHD. Autoplay and looping can be overwhelming or distracting for some users, so it may be appropriate to provide controls to allow the user to start and stop the content as needed.
  • Test the embedded content with a range of assistive technologies, such as screen readers and keyboard-only navigation, to ensure that it is fully accessible to users with disabilities. This can help identify any issues that may need to be addressed in order to improve the accessibility of the content.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes