The <iframe> element creates a nested browsing context: another document shown inside a rectangular frame on the current page.
Load a URL with src, or put markup directly in srcdoc. Always give a meaningful title for accessibility.
Baseline · Widely available.
Not deprecated. Core support has been stable across browsers since about July 2015. Some attributes (for example loading) still vary by browser.
Performance warning.
Each iframe is a full document environment and costs memory and network. Prefer fewer frames, and use loading="lazy" when the embed is off-screen.
Deprecated attributes.
frameborder, align, scrolling, marginwidth, marginheight, and longdesc are obsolete — use CSS for borders and overflow instead.
Syntax
HTML Syntax
syntax.html
<iframe src="url" title="label"></iframe>
Both start and end tags are required. Content between the tags is not a reliable fallback in modern browsers; put a normal link outside the frame if users may need another way in.
Reference
Attributes
The attributes you will use most often on <iframe>:
Set loading="lazy" so the browser can wait until the frame is near the viewport.
Keep a precise title — lazy loading does not replace accessibility labeling.
Optional referrerpolicy limits what referrer data the embed request sends.
Treat as enhancement: if loading is ignored, the iframe still works with eager load.
Watch out
Edge Cases & Pitfalls
a11y
Missing title
Without a title, assistive tech users must enter the frame to learn what it is. Always label embeds.
security
sandbox + same origin
Combining allow-scripts and allow-same-origin can let the framed page escape the sandbox.
cost
Too many frames
Every iframe has its own document. Check performance before stacking many embeds.
legacy
Prefer CSS over frameborder
Use border / overflow in CSS. Deprecated presentational attributes should not appear in new code.
events
error is unreliable
Browsers generally do not fire error on iframes, and load may still fire when content fails — do not probe URLs that way.
pdf
PDF + sandbox
sandbox can block the built-in PDF viewer. Offer a normal link outside the frame as a backup.
Compatibility
Browser Support
The <iframe> element is core HTML embedding in every browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
<iframe>
Widely available since about July 2015 (and earlier as HTML frames). Chrome, Firefox, Safari, Edge, and Opera all support it. Attributes such as loading and some Permissions Policy features vary.
98%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerAll
Supported
<iframe>Widely supported
Bottom line: Safe to use everywhere for basic embeds. Treat loading, allow, and newer sandbox tokens as progressive enhancements.
Remember
Key Takeaways
Role:<iframe> embeds another document in a nested browsing context.
Must-haves: meaningful title, explicit size, and a clear src or srcdoc.
Safety: use sandbox / allow thoughtfully for third-party or untrusted content.
Practice: prefer CSS over deprecated frame attributes; lazy-load off-screen embeds.
One line: embed with <iframe>, always title it, and sandbox untrusted content.
UA style
Default CSS Settings
User agents treat <iframe> as a replaced element. Typical defaults (exact values can vary):
default.css
iframe:not([hidden]) {
/* approximate UA defaults */
width: 300px; /* HTML width attribute default */
height: 150px; /* HTML height attribute default */
border: 2px inset;
}
Override size and border with CSS when you need a borderless or fluid embed. object-fit has no effect on iframes.
Frequently Asked Questions
The iframe element embeds another browsing context — typically another HTML page — inside the current page. Common uses are maps, videos, docs, and sandboxed previews.
Yes for accessibility. Screen reader users rely on title to know what the frame contains before entering it. Use a short, specific label.
src loads a URL. srcdoc embeds HTML markup directly in the attribute and overrides src when both are present. Browsers that lack srcdoc fall back to src.
Use sandbox when you embed untrusted or third-party content and want extra restrictions (scripts, forms, top navigation, and more). Add tokens only for what you must allow.
No. frameborder, align, scrolling, marginwidth, marginheight, and longdesc are deprecated. Control borders and scroll with CSS instead.
Same-origin frames can use contentWindow / contentDocument. Cross-origin access is blocked by the same-origin policy; use window.postMessage for safe messaging.