iframe – embedded page

<iframe src="url" title="description" width="600" height="400"></iframe>

An embedded page: a map, a video from a video service, a booking form, a payment gateway, an advert. The embedded page has its own document, styles and scripts and cannot affect the page around it unless both sides allow it.

  • Default display: display: inline
  • End tag: required
  • Content: nothing (content between the tags is never displayed)
  • Where it can be used: anywhere phrasing content is allowed
  • DOM interface: HTMLIFrameElement

Attributes

  • src – the URL of the embedded page; srcdoc – HTML inserted directly.
  • title – a description of the content for screen readers (“Map – 12 Mill Lane, Springfield”).
  • width, height – the dimensions in pixels (default 300 × 150).
  • loading – lazy: loads only when it gets close to the viewport.
  • sandbox – restrictions on the embedded page: without a value it blocks scripts, forms, pop-ups and access to its own cookies; values such as allow-scripts or allow-forms allow them one by one.
  • allow – allowed features: fullscreen, geolocation, camera, autoplay…
  • referrerpolicy, name (the target for links with target).

Examples

A map that loads only when the visitor scrolls towards the end of the page:

<iframe src="https://www.example.com/map?place=12+Mill+Lane" title="Map – 12 Mill Lane, Springfield" width="600" height="400" loading="lazy" style="border: 0"></iframe>

Third-party content with restricted rights – it may run scripts, but not open windows or change the URL of the page:

<iframe src="https://www.example.org/poll/" title="Poll" sandbox="allow-scripts" width="400" height="300"></iframe>

A full-width video with a 16 : 9 aspect ratio:

<iframe class="video" src="https://www.example.com/embed/abc" title="How to bake bread (video)" allow="fullscreen; picture-in-picture"></iframe>
.video {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
}

Accessibility

Every iframe needs a title – the screen reader announces it before the user enters the embedded page. The embedded page is navigated with the keyboard as part of the page.

Things to watch out for

  • An embedded page from another website can track visitors (third-party cookies) – for maps and videos this is often a reason for cookie consent.
  • sandbox with both allow-scripts and allow-same-origin makes no sense for a page from the same website – the script can remove the restrictions.
  • The default border is 2px inset, so a 300 × 150 frame takes up 304 × 154 px. border: 0 removes it.
  • Whether a page may be embedded is decided by its server (the X-Frame-Options header or frame-ancestors in CSP). Many websites forbid embedding.
  • loading="lazy" on iframe works in Chrome since 77, Firefox since 121 and Safari since 16.4 (as of October 2026).

Browser support

Baseline – widely available: works in all major browsers and has for a long time (since 2015 at the latest). Since version: Chrome 1, Firefox 1, Safari 4. As of October 2026 (MDN browser-compat-data).

Related:
embed – embedded content
object – external object
video – video
title – element tooltip (attribute)