embed Tag in HTML

1
110

The <embed> tag in HTML is used to embed external content into a web page, such as images, videos, audio files, and other types of multimedia content. In this tutorial, we’ll cover how to use the <embed> tag to add external content to your web pages.

Basic Usage

The basic syntax of the <embed> tag is as follows:

<embed src=”filename” type=”mediatype” />

Here’s a breakdown of the attributes used in this example:

  • src: This attribute specifies the URL of the external content you want to embed.
  • type: This attribute specifies the MIME type of the external content.

Let’s look at an example of how to use the <embed> tag to embed a video file:

<embed src=”video.mp4″ type=”video/mp4″ />

In this example, we’re embedding a video file called “video.mp4” using the <embed> tag. We also specify the MIME type of the video file as “video/mp4”.

Alternative Content

It’s a good idea to include alternative content for users who can’t view the embedded content, such as users who have disabled JavaScript or who are using screen readers. You can do this by using the <object> tag as a fallback.

Here’s an example of how to use the <object> tag as a fallback for the <embed> tag:

<embed src=”video.mp4″ type=”video/mp4″ />
<object data=”video.mp4″ type=”video/mp4″>
<p>Sorry, your browser doesn’t support embedded videos.</p>
</object>

Also Read:  tr Tag in HTML

In this example, we’ve included an <object> tag as a fallback for the <embed> tag. If the browser can’t display the video using the <embed> tag, it will try to display it using the <object> tag. If that fails, it will display the message “Sorry, your browser doesn’t support embedded videos.”

Styling the Embedded Content

You can use CSS to style the <embed> tag and its child elements. Here’s an example of how to use CSS to apply some basic styling to an embedded video:

<style>
embed {
width: 100%;
height: 400px;
}
</style>

<embed src=”video.mp4″ type=”video/mp4″ />

In this example, we use CSS to apply the following styles to the <embed> tag:

  • width: 100%; is used to make the embedded video fill the entire width of its container.
  • height: 400px; is used to set the height of the embedded video to 400 pixels.

Conclusion

The <embed> tag is a useful HTML element that allows you to embed external content, such as images, videos, and audio files, into your web pages. By using the <object> tag as a fallback and styling the embedded content with CSS, you can create a visually appealing and user-friendly layout that is accessible to all users.

1 COMMENT

Leave a Reply