⬅ Previous TopicHTML Geolocation API
Next Topic ⮕How to Integrate HTML and JavaScript
Embedding iframes in HTML
Embed Content with Examples & Responsive Design
Embedding iframes in HTML: Bring the Outside In
The <iframe>
tag lets you embed other web pages or media directly into your HTML. From YouTube videos to maps, documents, or custom dashboards, iframes are your window to external content — all from within your own page.
1. Basic iframe Syntax
<iframe src="https://example.com" width="600" height="400">
Your browser does not support iframes.
</iframe>
[ A 600x400 embedded frame showing https://example.com ]
The src
defines the URL to embed, while width
and height
define the size.
2. Attributes That Matter
| Attribute | Purpose | |----------|---------| |src
| URL of the content to embed |
| width
, height
| Size of the iframe |
| title
| Text for accessibility and screen readers |
| allowfullscreen
| Enables full-screen mode (e.g., for videos) |
| loading="lazy"
| Improves performance by loading iframe only when visible |
| referrerpolicy
| Controls the referrer header (e.g., no-referrer
) |
| sandbox
| Limits iframe's access to JavaScript and other features for security |
3. Example: Embedding a YouTube Video
<iframe width="560" height="315"
src="https://www.youtube.com/embed/banana123"
title="Banana Smoothie Tutorial"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
[ YouTube video appears with fullscreen option ]