Alternative to iFrames in HTML5


The HTML <iframe> tag specifies an inline frame (container). This inline frame is used to embed another document within the current HTML document. The "srcdoc" attribute of the <iframe> tag is used to specify the HTML content of the page to be displayed in the <iframe>.

HTML <embed> Tag

The alternative tag to iframe in HTML is tag. It is similar to the iframe tag which defines a container for external resources such as a picture, a webpage, a media player, or a plug-in application.

Following are the attributes of the HTML tag −

  • height − It specifies the height of the embedded content.

  • src − It specifies the address of the external file.

  • type − It specifies the media type of the embedded content.

  • width − It specifies the width of the embedded content.

Note − It is recommended to use the <img> tag for displaying a picture, <iframe> tag to display HTML, and <video>, <audio> tags to display video or audio.

Example

In the following example, we are using the <embed> tag as an alternative for <iframe> to embed an image onto the webpage. −

<!DOCTYPE html>
<html>
<head>
   <title>Embed tag in HTML</title>
   <style>
      embed {
            border: solid 2px black;
      }
   </style>
</head>
<body style="text-align: center;">
   <h2>Alternative for iframe is embed tag.</h2>
   <embed type="image/jpg" src="beach.jpg" width="300" height="200">
</body>
</html>

Example

Here, we are embedding an HTML page using the HTML <embed> tag −

<!DOCTYPE html>
<html>
<head>
   <title>Embed tag in HTML</title>
   <style>
      embed {
            border: solid 2px black;
      }
   </style>
</head>
<body style="text-align: center;">
   <h2>Alternative for iframe is embed tag.</h2>
   <embed type="text/html" src="https://www.tutorialspoint.com/index.htm" width="500px" height="350px">
</body>
</html>


Updated on: 04-Aug-2023

10K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements