Iframe Embed Code Generator

Generate an iframe with a responsive wrapper, lazy loading, a title for screen readers, and the sandbox and permission attributes that matter.

Live output

Enable JavaScript to customise; default output below.

Always HTTPS. A plain HTTP frame inside an HTTPS page is blocked as mixed content.

Read aloud by screen readers. An iframe without one is announced as "frame", which tells nobody anything.

Sizing

The responsive options use aspect-ratio, which every current browser supports.

Live preview embed.html
<style>
.embed-frame {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 9;
}

.embed-frame iframe {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	border: 0;
}
</style>

<div class="embed-frame">
	<iframe
		src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
		title="Product tour video"
		loading="lazy"
		allow="autoplay; picture-in-picture"
		allowfullscreen
		referrerpolicy="strict-origin-when-cross-origin"
	></iframe>
</div>

Output is valid and updates as you type.

Generate an iframe that scales with its container, loads only when it is needed, announces itself to screen readers, and grants the framed site only what it asks for.

How to use

  1. Use an HTTPS URL. A plain HTTP frame inside an HTTPS page is blocked as mixed content, and the embed simply does not appear.
  2. Write a real title. Screen readers announce an iframe by its title; without one the user hears “frame” and nothing else.
  3. Pick a responsive ratio unless the embed has a fixed size it must keep. aspect-ratio handles this in two lines now, with no padding-top trick.
  4. Lazy load anything below the fold. An embedded video that nobody scrolls to costs nothing.
  5. Grant the narrowest allow list that works. Each entry hands a capability to someone else’s page.

Example

<div class="embed-frame">
	<iframe
		src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
		title="Product tour video"
		loading="lazy"
		allow="autoplay; picture-in-picture"
		allowfullscreen
		referrerpolicy="strict-origin-when-cross-origin"
	></iframe>
</div>

youtube-nocookie.com is YouTube’s own privacy-preserving host: the same player, without the tracking cookie set until the video is played.

Pitfalls

  • An iframe with no title is announced as “frame” by screen readers, which is one of the most common accessibility failures on marketing pages.
  • sandbox="allow-scripts allow-same-origin" on a frame from your own origin removes the sandbox entirely: the framed page can reach out and remove its own restrictions.
  • sandbox="" blocks scripts, forms, popups and navigation. Most real embeds need at least allow-scripts.
  • loading="lazy" on an iframe above the fold delays something the visitor is already looking at.
  • The allow attribute is a permissions policy, not a suggestion. Granting camera or geolocation to an embed hands that capability to the other site.
  • An iframe blocks nothing by default: the framed site can run scripts, set cookies and navigate the top window unless you sandbox it.
  • Fixed width and height attributes overflow on a phone. The responsive wrapper exists for that.
  • Third-party embeds pull in their own scripts and cookies. A cookie banner that claims no third-party cookies while an embed sets them is a compliance problem, not a technical one.

Compatibility

loading="lazy" on iframes is supported in Chrome, Edge, Firefox and Safari 16.4 and later; older Safari loads eagerly, which is the previous behaviour rather than a break. aspect-ratio is supported by every current browser. allow needs a browser with Permissions Policy, which is all Chromium browsers, Firefox and Safari. sandbox and referrerpolicy are universal. The tool runs entirely in your browser.

Frequently asked questions

Why is my embed not showing?
Either the URL is HTTP inside an HTTPS page, or the framed site sends X-Frame-Options or a frame-ancestors policy that refuses to be framed. Neither is something you can fix from this side.
How do I make it responsive?
Wrap it and set aspect-ratio on the wrapper, which is what the generated CSS does. The old padding-top trick is no longer needed.
Is sandbox worth using?
For anything you do not control, yes. Start with allow-scripts and add back only what breaks.
Should I lazy load?
Below the fold, always. Above it, never: you are delaying something already on screen.
What about YouTube privacy?
Use youtube-nocookie.com. It serves the same player and holds off the tracking cookie until playback starts.
Weekly drops

New tools, when there are new tools

One email when something worth using ships. No schedule to fill, so no filler.

Your address goes nowhere else, and one click unsubscribes.