What Is an Iframe?
An HTML element that embeds another web page, such as a YouTube player, inside the current page.
An iframe (inline frame) is a standard HTML element, <iframe>, that loads a separate web document inside a rectangular area of the current page. YouTube’s video player is delivered this way: the surrounding page stays yours, while the framed area runs YouTube’s own player code.
Why YouTube uses an iframe
Because the player runs in its own frame, it is sandboxed from the rest of the page for security, gets automatic updates from YouTube without the embedding site changing anything, and can be swapped between the standard youtube.com domain and the privacy-enhanced youtube-nocookie.com domain simply by changing the source URL.
Common iframe attributes for video embeds
The most relevant ones are src (the embed URL and its parameters), title (for screen readers), allow (which permissions the frame gets, such as autoplay or fullscreen), allowfullscreen, and loading=”lazy” for performance.
How an iframe fits into the rest of a web page
A web page is normally one continuous HTML document, but an iframe creates a boundary: everything inside it is a separate document, with its own scripts, styles and browsing context, rendered inside a box you position with ordinary CSS. This isolation is a security feature as much as a technical one. A page embedding a YouTube iframe cannot directly read or modify what happens inside the YouTube player, and the player cannot directly read or modify the rest of your page, beyond what each side explicitly allows through browser APIs.
A practical example
The difference between an iframe and simply linking to a page is immediately visible if you compare the two side by side. A link, <a href="https://youtube.com/watch?v=ID">Watch on YouTube</a>, takes a visitor away from your page entirely. An iframe, <iframe src="https://www.youtube-nocookie.com/embed/ID"></iframe>, keeps the visitor on your page while showing YouTube’s player inside a defined area. The src attribute is doing very different jobs in each case: navigation target versus embedded document source.
Iframe vs. other embedding techniques
Iframes are not the only way to bring in external content, but they are the standard approach for a fully interactive third-party application like a video player. Alternatives such as embedding a static image or a link preview card show far less: they cannot offer playback controls, cannot stream video data, and cannot respond to user interaction the way an iframe-based player does. For anything requiring real interactivity from another origin, video players, maps, payment widgets, an iframe (or the more specialised APIs built on top of one) is generally the only practical option. See embed code for how an iframe is packaged into the HTML you actually paste onto a page.
Frequently asked questions
What is an iframe in simple terms?
An iframe is an HTML element that loads a separate web page, such as YouTube’s video player, inside a rectangular area of the current page.
Is an iframe the same as an embed code?
An embed code is the full HTML snippet; the iframe is the specific tag inside it that does the actual embedding.
Build your embed code
Our generator writes a privacy friendly embed code you can paste straight into your page.