An HTML iframe (inline frame) embeds another document inside the current page. Use the <iframe> element with a src URL (or srcdoc markup) so visitors can view maps, docs, hosted players, or other pages without leaving your site.
What are iframes for in an HTML tutorial?
Show a nested page, a map widget, or a video player from another host. The frame has its own browsing context—separate scroll, history, and (often) origin from the parent page.
Where can you place iframes?
Inside the <body>, typically where you want the embedded surface to appear. Pair every iframe with a meaningful title. Prefer CSS for borders and responsive width; avoid obsolete attributes like frameborder.
When should you use them?
When a third party already hosts the experience (maps, video, forms) or you need a sandboxed preview. Prefer native <video>/<audio> for your own media files.
Always set title.
Assistive tech uses title to describe the frame. A missing or vague title makes embeds hard to navigate.
Trust the src.
Third-party pages can run scripts inside the frame. Use sandbox (and allow) when you embed untrusted or third-party content.
Default size.
Without sizing, iframes are often 300×150 CSS pixels. Set width/height or CSS so layout stays stable.
src is the page to load. title is required for accessibility. Optional: name (link target), sandbox, loading, referrerpolicy, allow, and srcdoc for inline HTML.
Reference
Core HTML Concepts
Attributes and ideas you will use most often:
Concept
Meaning
src
URL of the document to embed
title
Accessible name announced by screen readers
width / height
Frame size in CSS pixels (or use CSS)
sandbox
Extra restrictions; tokens re-enable specific features
loading="lazy"
Defer fetch until near the viewport
name
Target name for links (target="framename")
srcdoc
Inline HTML to show instead of (or as fallback for) src
Border
Style with CSS (border: none), not frameborder
sandbox tokens (common)
Token
Allows
(empty sandbox)
Maximum restrictions
allow-scripts
Run scripts (not popups by itself)
allow-forms
Form submission
allow-same-origin
Treat content as same-origin (use carefully with scripts)
allow-popups
Open new windows/tabs
Approach
How to Use Iframes in HTML
Practical habits for safe, accessible embeds.
Set src to the embed URL from the provider (or your own page).
Add a clear title that describes the framed content.
Give explicit width and height (or CSS aspect-ratio wrappers).
Remove or restyle the default border with CSS.
Add sandbox for untrusted content; allow only needed tokens.
Use loading="lazy" for embeds that start off-screen.
Goal
Pattern
Basic embed
<iframe src="…" title="…">
Sized frame
width="500" height="300" or CSS
No border
style="border:none"
Safer third party
sandbox="allow-scripts allow-forms"
Performance
loading="lazy"
Link into frame
name on iframe + target on <a>
Try it
Live Preview
Switch modes to compare a basic embed, a sized borderless frame, and a sandboxed preview.
Uses srcdoc so the demo works without an external network page.
Rendered page
Code
HTML Examples
Six patterns: basic src/title, size, borderless CSS, sandbox, lazy loading, and a map embed.
loading="lazy" suits maps that start lower on the page.
Same pattern works for docs viewers and many hosted widgets.
Edge Cases & Pitfalls
Broken embeds usually come from missing titles, oversized unrestricted frames, or X-Frame-Options / CSP blocks.
a11y
Missing or vague title
Screen reader users hear “iframe” with no context. Name the content specifically.
block
Site refuses to be framed
Many sites send X-Frame-Options or CSP frame-ancestors. You cannot force them into an iframe.
sandbox
Over-permissive sandbox
allow-scripts + allow-same-origin can let framed content remove sandboxing. Prefer the least privilege.
layout
No reserved size
Unset dimensions cause jank when the frame loads. Set width/height or a CSS aspect-ratio box.
legacy
Deprecated attributes
frameborder, scrolling, align, and margin attributes are obsolete—use CSS instead.
perf
Eager third-party weight
Each iframe can pull heavy scripts. Lazy-load off-screen embeds and avoid stacking many third-party frames above the fold.
Compatibility
Browser Support
The iframe element is part of HTML and works in all modern browsers. Prefer CSS over deprecated frame attributes.
✓ Baseline · Widely available
HTML iframes
Every current browser embeds nested documents with iframe. sandbox and loading="lazy" are widely supported in modern engines.
100%iframe element
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
HTML iframeUniversal
Bottom line: Use iframe with src, title, and sensible sizing—add sandbox and lazy loading when the embed warrants it.
Remember
Key Takeaways
<iframe> embeds another document via src (or srcdoc).
title is required for accessibility; size the frame explicitly.
sandbox hardens third-party or untrusted content.
loading="lazy" helps performance for off-screen embeds.
One line: Embed with <iframe src="…" title="…">, size it, style the border in CSS, and tighten third-party content with sandbox and lazy loading when needed.
Frequently Asked Questions
An iframe (inline frame) embeds another HTML document inside the current page. The nested page loads in its own browsing context, controlled mainly by the src attribute.
Screen readers announce the title so users know what the frame contains before entering it. Always set a short, specific title—never leave it blank or generic like "iframe".
Without size attributes or CSS, browsers typically render an iframe about 300px wide and 150px high. Set width and height (or CSS) so layout does not jump when content loads.
sandbox applies extra restrictions: unique origin, no scripts, no forms, no top navigation, and more. Add space-separated tokens such as allow-scripts only for capabilities you intentionally need.
Use loading="lazy" for iframes below the fold so the browser can defer fetching them until they are near the viewport. Keep above-the-fold embeds eager (the default).
Yes. Many services provide an embed URL for iframe src. Always add title, size the frame, and review sandbox/allow permissions the provider documents.