Skip to content

HTML Plug-ins

Beyond basic HTML, you sometimes need to embed content from other sources or of different types directly into your web pages.

Historically, browsers relied on external plug-ins (like Adobe Flash Player or Java Applets) to handle multimedia or interactive content not natively supported by HTML. These were often embedded using <object> or the non-standard <embed> tag.

Important: Browser plug-ins like Flash and Java Applets are now obsolete and deprecated. They suffered from major security vulnerabilities, poor performance, and lack of support on mobile devices. Modern web development avoids them entirely.

Native HTML5 features like <video>, <audio>, <canvas>, and SVG have replaced the need for most plug-ins.

Today, we use standard HTML elements to embed various types of external content:

  • <iframe>: The most common way to embed an entire, independent HTML document within the current page. Used for embedding maps (Google Maps), videos (YouTube, Vimeo), external web pages, or ads.
  • <embed>: A standard HTML5 element for embedding external content, often plugin content historically, but can technically embed various resource types (like PDFs or SVGs). It’s a void element (no closing tag).
  • <object>: A more versatile element than <embed>. It can embed various resource types (PDFs, SVGs, even other HTML documents) and allows for fallback content within the <object> tags if the primary resource cannot be displayed.
  • <img>: Used specifically for embedding images (JPEG, PNG, GIF, SVG, WebP, AVIF).
  • <video> and <audio>: Used specifically for embedding video and audio files directly. (Covered in detail in the HTML Media chapter).

The <iframe> (Inline Frame) element embeds another HTML document in a nested browsing context.

Example: Embedding a map (conceptual - actual map embed code varies by provider)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Iframe Example</title>
<style>
iframe {
border: 1px solid #ccc;
width: 100%; /* Make it responsive */
max-width: 600px; /* Optional max width */
height: 450px;
}
</style>
</head>
<body>
<h2>Our Location</h2>
<iframe
src="https://www.openstreetmap.org/export/embed.html?bbox=-0.1278%2C51.5074%2C-0.1277%2C51.5075&layer=mapnik"
title="Location Map via OpenStreetMap"
loading="lazy" /* Defer loading until needed */
allowfullscreen /* Allow entering fullscreen mode */
sandbox="allow-scripts allow-same-origin"> <!-- Security: Restrict iframe capabilities -->
<p>Your browser does not support iframes. <a href="https://www.openstreetmap.org/..." target="_blank">View map directly</a></p>
</iframe>
</body>
</html>

Key <iframe> attributes:

  • src: URL of the document to embed.
  • width, height: Dimensions (though CSS is often preferred for responsive control).
  • title: Important for accessibility, describes the iframe content.
  • loading="lazy": Defers loading until the iframe is near the viewport.
  • allowfullscreen: Permits the iframe content to enter fullscreen mode.
  • sandbox: A crucial security attribute to restrict the capabilities of the embedded content (e.g., prevent scripts, form submissions, popups).

The <object> element can embed various types of external resources, like PDFs or SVGs. It allows providing fallback content inside its tags.

Example: Embedding a PDF

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object Element Example</title>
<style>
object {
width: 100%;
height: 500px;
border: 1px solid #eee;
}
</style>
</head>
<body>
<h2>Document Viewer</h2>
<object data="documents/report.pdf" type="application/pdf">
<p>It appears you don't have a PDF plugin for this browser.
You can <a href="documents/report.pdf">download the PDF file</a> instead.</p>
</object>
</body>
</html>

Key <object> attributes:

  • data: URL of the resource to embed.
  • type: The MIME type of the resource (e.g., application/pdf, image/svg+xml). Helps the browser decide how to handle it.
  • width, height: Dimensions.

The <embed> element also defines an integration point for external content. It’s simpler than <object> but offers less control and no built-in fallback mechanism.

<embed> is a void element (no closing tag).

Example: Embedding an SVG (though <img> or <object> are often preferred for SVGs)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Embed Element Example</title>
</head>
<body>
<h2>Embedded SVG Logo</h2>
<embed src="images/logo.svg" type="image/svg+xml" width="100" height="100">
</body>
</html>

Key <embed> attributes:

  • src: URL of the resource.
  • type: The MIME type of the resource.
  • width, height: Dimensions.

Generally, prefer <iframe> for embedding HTML documents and <object> or specific elements like <img>, <video>, <audio> for other resource types due to better fallback and control options.