<iframe> Tag in HTML

Quick facts

CategoryFlow content, phrasing content, embedded content, interactive content, palpable content
Content modelNothing
Tag omissionNeither the start nor the end tag can be omitted
Permitted parentsAny element that accepts embedded content
DOM interfaceHTMLIFrameElement

Syntax

<iframe src="https://www.youtube.com/embed/VIDEO_ID" title="Video title" width="560" height="315" loading="lazy" allowfullscreen></iframe>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

AttributeDescription
srcThe URL of the page to embed
srcdocHTML to show directly instead of loading a URL
titleDescribes the frame’s content for screen readers — always add one
width / heightThe frame size in pixels (default 300 × 150)
loadinglazy waits until the frame is near the screen; eager (default) loads at once
allowFeatures the embedded page may use, e.g. fullscreen; autoplay; clipboard-write
allowfullscreenLets the embedded page go full screen (common for videos)
sandboxApplies strict restrictions; add tokens like allow-scripts to relax them one by one
referrerpolicyHow much of your page’s URL is sent to the embedded site
nameA name that links and forms can target with target="name"

Common examples

A responsive YouTube video

Paste the embed code from YouTube’s Share → Embed, then let CSS size it to the page while keeping the 16:9 shape.

<iframe src="https://www.youtube.com/embed/VIDEO_ID" title="How to build a website" loading="lazy" allowfullscreen></iframe> <style> iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; border: 0; } </style>

An embedded Google Map

In Google Maps choose Share → Embed a map, copy the code, and add loading="lazy" so it only loads when scrolled into view.

<iframe src="https://www.google.com/maps/embed?pb=…" title="Map to our shop" width="600" height="400" loading="lazy" style="border:0"></iframe>

A sandboxed third-party widget

The sandbox attribute blocks everything by default; add back only what the widget needs.

<iframe src="https://widget.example.com/" title="Booking widget" sandbox="allow-scripts allow-forms"></iframe>

<iframe> vs <embed> and <object>

An <iframe> embeds a whole web page — a video player, a map, a form — that runs in its own frame with its own scripts and links. <embed> and <object> embed a single file, such as a PDF or an SVG image, and are mainly used for formats the browser can display directly.

For YouTube, Vimeo, maps and other services, use the iframe embed code they provide. For a PDF on your own site, <object> with a download link inside as a fallback is the friendliest option.

<iframe><embed> / <object>
EmbedsA whole web pageA single file
Typical useVideos, maps, widgetsPDFs, SVG files
Security controlssandbox, allowLimited

Common mistakes to avoid

  • Missing title. Screen readers announce the title to say what’s inside the frame; without it the frame is a mystery.
  • Fixed widths that break on phones. A 560-pixel-wide frame overflows small screens; use width: 100% with aspect-ratio.
  • Several heavy embeds loading at once. Each video or map loads lots of extra code. Lazy-load them, or show a thumbnail that loads the player on click.
  • Embedding untrusted content without a sandbox. Third-party frames can run scripts; restrict them with sandbox and allow.

Accessibility & SEO tips

  • Always set a short, descriptive title such as “Map to our shop” or “Video: How to bake bread”.
  • Use loading="lazy" on iframes below the first screen to keep your page fast, which also helps Core Web Vitals.
  • Text inside an iframe usually counts for the embedded page, not yours — keep your important content directly on your own page so it can rank.

Browser support

Supported in every browser. The loading="lazy", sandbox and allow attributes work in all current browsers.

Related tags

Frequently asked questions

Why does my iframe say the site "refused to connect"?
Many websites, including Google and most banks, forbid being embedded using the X-Frame-Options or Content-Security-Policy headers. You can't override that; link to the page instead, or use the site's official embed code.
How do I make an iframe responsive?
Remove the fixed width and height and use CSS: iframe { width: 100%; aspect-ratio: 16 / 9; height: auto; }. The frame then scales with the page while keeping its shape.
Are iframes bad for SEO?
Content inside an iframe generally counts for the embedded page, not yours. Embedding a video or map is fine, but put your main text directly on your own page so it can rank.
How do I remove the border around an iframe?
Use CSS: iframe { border: 0; }. The old frameborder attribute is obsolete, so set the border in CSS instead.
How do I embed a Google Map on my website?
Open the place in Google Maps, click Share, choose "Embed a map", pick a size and copy the HTML. Paste the <iframe> code into your page and add loading="lazy".
Can I change the content inside an iframe from another website?
No. Browsers block scripts on your page from reading or changing a frame that comes from a different domain (the same-origin policy). You can only style the frame itself.