Hosting video yourself means handling encoding, storage, bandwidth and adaptive quality. For most sites an embed from a video platform is the sensible choice. What arrives with it is an entire page from another site, loaded inside yours, and that has consequences worth managing.
What an iframe is
An iframe embeds a separate document within the current one. It has its own address, its own stylesheet, its own scripts and its own network requests, and your CSS cannot reach inside it.
<iframe src="https://example.com/embed/abc123" width="560" height="315" title="Introduction to CSS Grid" loading="lazy" allowfullscreen></iframe> It is not a void element and requires a closing tag, though it takes no content.
The title attribute is required here
Unusually, this is a case where a title attribute genuinely matters. Screen reader users can navigate between frames, and without a title an embed is announced only as a frame, giving no indication of what it contains.
Describe the content rather than the mechanism. Naming the video is useful, whereas a generic label naming the platform is not, particularly on a page with several embeds.
Lazy load them
Embeds are heavy. A video player typically pulls in a substantial amount of script and makes numerous requests before anyone has decided to watch anything. On a page where the video sits below the fold, that cost is paid by every visitor whether or not they scroll to it.
The loading attribute set to lazy defers the whole embed until it approaches the viewport, and it is one of the highest impact single attributes available on a content heavy page.
Making them responsive
An iframe has fixed dimensions and does not scale like an image. The old solution was a wrapper with padding calculated from the aspect ratio, which worked and was opaque. CSS now handles it directly.
.embed { aspect-ratio: 16 / 9; width: 100%; } .embed iframe { width: 100%; height: 100%; border: 0; } Declaring the ratio on the container reserves correct space before the frame loads, which prevents layout shift as well as making it responsive.
The facade pattern
Even lazy loaded, an embed that comes into view loads everything. A facade replaces it with a static image of the poster frame and a play button, and only inserts the real iframe once the visitor clicks.
The result is that visitors who never play the video never pay for the player at all. On pages with several videos the difference is dramatic, and the pattern is common enough that libraries exist for it. The trade off is that the first click costs a moment while the player initialises.
Privacy and tracking
An embed usually sets cookies and reports data to the platform whether or not anyone presses play. In jurisdictions with consent requirements, that makes an embed something you may need permission to load, not merely something you should mention in a policy.
Most platforms offer a privacy preserving domain that defers tracking until playback begins, which is a straightforward improvement and worth using by default. A facade helps here too, since nothing from the third party loads until the visitor has chosen to engage.
Sandboxing untrusted content
Where you embed content you do not control, the sandbox attribute restricts what the framed document may do, disabling scripts, forms, popups and navigation of the parent unless explicitly permitted.
This is essential for user supplied embeds and unnecessary for a major video platform, whose player requires scripting anyway. The related allow attribute controls access to features such as fullscreen, autoplay and picture in picture, and granting only what the embed needs is good practice.
Other embeds follow the same rules
Maps, social media posts, code sandboxes, forms and payment widgets are all iframes, and everything above applies to them equally. Each needs a title, most benefit from lazy loading, and all bring third party weight and tracking with them.
A page carrying several different embeds can easily transfer more from other domains than from your own. Auditing which are genuinely earning their place is often the single largest performance improvement available, ahead of anything you can do to your own code.
What you give up
An embed means the player interface, the branding, the recommendations shown afterwards and the data collected are all outside your control. For most sites that trade is worth it against the cost of self hosting.
Where the video is short, decorative or central to your brand, a self hosted video element with your own poster image gives you complete control and avoids the third party weight entirely.