MyInternships.in

HTML Basics

HTML Iframes

An iframe embeds another web page inside your page, like a window into a different document. It is commonly used to display maps, videos, and widgets.


What is an HTML Iframe?

An iframe (inline frame) is created with the <iframe> tag. Its src attribute points to another web page, which is then displayed in a rectangular area inside your own page. Think of it as a mini-browser embedded in your document.

Iframes are widely used to embed third-party content — YouTube videos, Google Maps, payment widgets, and code demos — without copying that content onto your own server.

Basic Usage

Embedding a page
Example
<iframe src="https://example.com" width="400" height="250" title="Example site"></iframe>

Example: Iframe With a Border and Title

A framed page
Example
<!DOCTYPE html>
<html>
<body>
  <h2>An embedded page</h2>
  <iframe src="https://example.com"
          width="100%" height="300"
          title="Example.com homepage"
          style="border:2px solid #0d6efd; border-radius:8px;">
  </iframe>
</body>
</html>

More Examples

Embedding a YouTube video
Example
<iframe width="420" height="236"
        src="https://www.youtube.com/embed/dQw4w9WgXcQ"
        title="Embedded video"
        allowfullscreen>
</iframe>
A link that loads into a named iframe
Example
<!DOCTYPE html>
<html>
<body>
  <a href="https://example.com" target="viewer">Load example.com below</a>
  <br><br>
  <iframe name="viewer" width="100%" height="250" title="Viewer"></iframe>
</body>
</html>

Common iframe Attributes

AttributePurpose
srcThe URL of the page to embed.
width / heightThe size of the frame.
titleA description for accessibility (required).
allowfullscreenLets embedded video go full screen.
sandboxRestricts what the embedded page can do.
loadingSet to "lazy" to defer loading.
⚠️

Many sites block being embedded using the X-Frame-Options header, so some pages will simply show blank in an iframe. Only embed content that permits it.

💡

Always add a title attribute to iframes. Screen readers use it to announce what the embedded frame contains. Use the sandbox attribute for untrusted content.

Key Takeaways

  • An <iframe> embeds another web page inside yours.
  • src sets the embedded URL; width and height set the size.
  • Add a title for accessibility and use sandbox for safety.
  • Some sites block embedding and will appear blank.

Related HTML Topics

Keep learning with these closely related tutorials.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships