The <iframe> element (short for inline frame) embeds a separate HTML document in your page. The embedded page loads from its own URL and keeps its own HTML, styles and scripts. Your page just gives it a rectangle to appear in.
That's why iframes are the usual way to add things you don't host yourself: a YouTube video, a Google map, a booking widget, a payment form or an ad.
What an iframe looks like
A typical embed, with the attributes worth setting:
<iframe
src="https://www.example-maps.com/embed?place=berlin-office"
title="Map of our Berlin office"
width="600" height="400"
loading="lazy">
</iframe>
srcis the page to embed.titlenames the frame for people using screen readers. Without it, they have to go into the frame to find out what it is.widthandheightset the size in CSS pixels. Leave them out and browsers draw a 300 by 150 box.loading="lazy"waits to load the frame until the reader scrolls near it.
How the embedded page stays separate
Each iframe is a complete page of its own. If it comes from another site (another origin), the browser's same-origin policy stops scripts on either side from reading or changing the other's content. The two pages can still exchange messages on purpose with postMessage().
This separation is what makes iframes safe enough for third-party content. It's also why styling and resizing an embed from the outside is limited.
What iframes mean for SEO
The content inside an iframe belongs to its own URL, not to your page. Google says that during indexing it can embed the content of a framed page in the page that embeds it, as long as the framed page allows it (see below). Even then, that content is still someone else's page, or another of yours. So:
- Put your own main content in your page's HTML, not in an iframe.
- Use iframes for supporting extras, like a map or a video, where it doesn't matter whether the words inside count as your page's text.
If you publish content that others embed, such as a podcast player or a video, you have one extra option. A noindex rule on the embeddable page keeps it out of Google, and Google says it also prevents embedding that content in other pages during indexing. Add indexifembedded next to noindex, and Google will keep the page itself out of results but may still index its content where it's embedded. Google says that, for now, it's the only search engine that supports this rule. Google Search Central
<meta name="googlebot" content="noindex, indexifembedded">
You can send the same rule in an X-Robots-Tag header.
Iframes and page speed
Every iframe loads a whole page: its HTML, scripts, fonts and images. A few embeds can add more weight than the rest of your page, and each one takes extra memory in the browser.
Three habits keep that in check:
- Add
loading="lazy"to iframes further down the page. Google lists the browser's built-in lazy loading as a method it can handle, because it doesn't wait for a scroll or a click. Don't lazy-load a frame that's visible as soon as the page opens; that only delays it. - Set
widthandheight(or a CSS aspect ratio) so the browser reserves the space. Otherwise the page can jump when the frame appears, which hurts Cumulative Layout Shift. - For heavy players, show a lightweight preview image first and load the real iframe when someone clicks it.
See lazy loading for how deferred loading works in general.
Security: limit what an embed can do
Third-party code runs inside your page's frame, so it's worth restricting it:
sandboxwith no value applies every restriction: no scripts, no forms, no pop-ups. Add tokens such asallow-scriptsorallow-formsto lift only what the embed needs. Don't combineallow-scriptsandallow-same-originfor a page from your own site: together they let the framed page remove the sandbox.allowsets which browser features the frame may use, such as the camera, microphone or fullscreen.referrerpolicycontrols how much of your page's address is sent to the embedded site.
The opposite question is who may put your pages in their iframes. To stop other sites from framing your pages (a trick used in clickjacking), send the Content-Security-Policy: frame-ancestors header, for example frame-ancestors 'self'. The older X-Frame-Options header does a similar job. MDN
When not to use an iframe
If the content is yours and you want it to rank, put it in the page. If you only need to show one image, file or video you host, <img>, <video> or a plain link usually does the job with less code. Keep iframes for content that really lives somewhere else.