Live Preview
Embedded YouTube video player (requires network access):

By the end of this tutorial, you’ll embed external content — maps, videos, and web pages — using the <iframe> element safely and accessibly.
The <iframe> (inline frame) tag is a powerful HTML tool for integrating third-party content into your pages. This guide covers syntax, attributes, security, accessibility, and best practices for beginners and web developers alike.
Set src, dimensions, and a descriptive title.
Integrate Google Maps, YouTube, and other widgets.
Choose the right element for pages vs media files.
Use sandbox and trusted sources to reduce risk.
Control borders, sizing, and responsive layout with CSS.
Add titles, fallback content, and keyboard-friendly embeds.
<iframe> Tag?The inline frame element (<iframe>) embeds another HTML document inside the current page, creating a nested browsing context. It is commonly used for maps, video players, social feeds, payment forms, and other third-party widgets.
An iframe loads a separate document with its own URL. The embedded content runs in its own context, which is why security and accessibility attributes matter.
Unlike obsolete frame and frameset tags, iframe works inside a normal HTML5 document body. It remains one of the standard ways to embed external interactive content today.
Point the src attribute at the URL you want to embed and set dimensions plus a descriptive title:
<iframe
src="https://example.com/embed"
title="Description of embedded content"
width="600"
height="400"
loading="lazy"
></iframe>src is required — it specifies the URL of the embedded document.title attribute describing the embedded content for accessibility.width and height (or use CSS) so layout does not jump while loading.frameborder — remove borders with CSS (border: none).| Use Case | Code Snippet | Notes |
|---|---|---|
| Basic embed | <iframe src="..." title="..."></iframe> | Nested browsing context |
| Google Maps | src="maps.google.com/embed?..." | Use embed URL from Maps share dialog |
| YouTube video | src="youtube.com/embed/VIDEO_ID" | Add allow permissions |
| Lazy loading | loading="lazy" | Defers off-screen iframes |
| Security | sandbox="" | Restrict embedded page capabilities |
| Remove border | CSS: border: none; | Replaces obsolete frameborder |
<iframe> vs <embed>Both insert external content, but they serve different purposes:
| Feature | <iframe> | <embed> |
|---|---|---|
| Element type | Container with closing tag | Void element |
| Typical content | HTML pages, maps, widgets | Media files, PDFs |
| Nested browsing context | Yes — separate document | No |
| Key attributes | src, title, sandbox | src, type |
<iframe> vs obsolete <frame>Modern pages use iframe inside a normal document. Obsolete framesets split the entire window:
| Feature | <iframe> (modern) | <frame> (obsolete) |
|---|---|---|
| Status | Valid HTML5 | Obsolete — do not use |
| Placement | Anywhere in the page body | Inside frameset only |
| Layout | CSS grid/flex with iframes | Fixed window panes |
| Accessibility | title + fallback content | Poor navigation for assistive tech |
Key <iframe> attributes plus global attributes such as class and id:
src RequiredURL of the document or embed widget to load inside the frame.
src="https://example.com"title RequiredAccessible name describing the embedded content for screen readers.
title="Map of London"width / height LayoutDimensions in pixels or CSS units to reserve space before content loads.
width="560" height="315"allow PermissionsFeature policy for fullscreen, autoplay, camera, microphone, and more.
allow="fullscreen"sandbox SecurityRestricts scripts, forms, and navigation in untrusted embedded content.
sandbox=""loading PerformanceDefer loading off-screen iframes with loading="lazy".
loading="lazy"<iframe
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
width="560"
height="315"
loading="lazy"
allow="fullscreen"
allowfullscreen
></iframe>Avoid obsolete frameborder. Use CSS border: none; instead. Match allow permissions to what the embedded widget actually needs.
Google Maps, YouTube video, and basic iframe patterns with copy-ready code and live previews.
Embedded YouTube video player (requires network access):
Embed an interactive map to show location details and improve user engagement.
<iframe
src="https://www.google.com/maps/embed?pb=..."
title="Map of London, UK"
width="600"
height="450"
loading="lazy"
allowfullscreen
></iframe>Use <iframe> to integrate maps, video players, social widgets, payment forms, and documentation previews. For your own video and audio files, prefer <video> and <audio> with native controls.
Integrate multimedia content by embedding a YouTube player directly in your page.
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
loading="lazy"
allow="fullscreen"
allowfullscreen
></iframe>Modern syntax with title, lazy loading, and fallback content for unsupported browsers.
<iframe
src="https://example.com"
title="Example website preview"
width="480"
height="200"
loading="lazy"
>
<p>Your browser does not support iframes.
<a href="https://example.com">Visit example.com</a>.
</p>
</iframe>Replace obsolete frameborder with CSS. Make iframes responsive with max-width and aspect-ratio:
border: none Remove default bordermax-width: 100% Responsive sizingaspect-ratio 16:9 video embedsborder-radius Rounded corners/* Remove obsolete frameborder — use CSS instead */
iframe {
border: none;
display: block;
max-width: 100%;
}
iframe.video-embed {
width: 100%;
max-width: 560px;
aspect-ratio: 16 / 9;
border-radius: 8px;
}
iframe.map-embed {
width: 100%;
min-height: 280px;
border: 1px solid #cbd5e1;
border-radius: 8px;
}Responsive video embed styling
Embedded content must remain usable for all visitors:
Point src at the embed URL and describe the content with title.
The browser fetches and renders the external page inside a separate browsing context.
Maps, videos, and forms inside the iframe run independently from the parent page.
External content appears seamlessly within your page layout.
The <iframe> element is fully supported in all browsers, including legacy Internet Explorer.
From legacy Internet Explorer to the latest mobile browsers — the iframe element is fully supported for nesting external documents.
Bottom line: Ship embedded widgets with confidence. The <iframe> element is safe to use in every production environment today.
Mastering the <iframe> tag lets you seamlessly integrate maps, videos, widgets, and external pages into your site. Set dimensions, add a descriptive title, and follow security best practices for a dynamic user experience.
Remember to replace obsolete frameborder with CSS, choose iframe over obsolete frame, and prefer native video and audio tags for your own media files.
width, height, and title on every iframeborder: none instead of frameborderloading="lazy" for below-the-fold embedstitle attributesandbox restrictionsvideo instead<iframe>Bookmark these before you ship — they’ll keep your embeds secure and accessible.
<iframe> loads a separate page inside yours.
Describe embedded content for screen reader users.
Accessibilityiframe = HTML page; embed = media file.
Restrict untrusted embedded content with sandbox.
SecurityRemove borders with CSS, not obsolete attributes.
Modern HTMLWorks in every browser, including legacy IE.
Compatibilityiframe nests a full HTML browsing context. embed inserts external media files like PDFs directly.border: none; instead. The frameborder attribute is obsolete in HTML.title to announce what the embedded content is. Without it, users cannot identify the iframe.Embed maps, videos, and external pages in the interactive HTML editor.
6 people found this page helpful