Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

iframe

The iframe element embeds external content with responsive containers and security best practices for third-party integrations.

Description

The <iframe> element embeds another HTML document within the current page. VB removes the default border, makes the frame block-level and never wider than its container, and offers variant classes, a data-ratio attribute for proportional sizing, and ratio wrappers for common embeds.

When to Use

  • Video embeds: YouTube, Vimeo, and other video platforms
  • Maps: OpenStreetMap and other map embeds (or <geo-map> for a tile map you control)
  • Social widgets: Timelines and posts
  • Payment forms: Hosted checkout fields
  • Third-party tools: Calendars, forms, surveys
  • Untrusted HTML: User-supplied markup rendered with sandbox and srcdoc

When to Use Other Elements

  • Use <video> for self-hosted video files
  • Use <audio> for self-hosted audio
  • Use <dialog> for modal content on your own page
  • Use <object> for PDFs that need a download-link fallback

Variants

VB removes the default iframe border and provides variant classes for visual style and width.

ClassEffect
(default)No border, block display, max-inline-size: 100%. Size comes from the width/height attributes (UA default 300×150).
.borderedSubtle border with rounded corners
.roundedMedium border radius, overflow hidden
.full100% container width; the height attribute is kept
.fixed100% width, fixed 400px height (overrides height)

Responsive Sizing with data-ratio

An iframe has no natural aspect ratio, so its width and height attributes don't scale together: on a narrow screen max-inline-size clamps the width and leaves the full height, giving a tall letterbox. Put data-ratio on the iframe itself and the block size follows the used width instead.

  • A width attribute stays the preferred (maximum) width; without one the iframe fills its container.
  • Keep integer width/height as the no-CSS fallback.
  • Values: 1:1, 4:3, 3:2, 16:9 (default), 21:9, 2:3, 3:4, 9:16, and page (1 : 1.414, a portrait document page). The same vocabulary works on <embed> and <object>.

The data-media wrapper

When an embed needs a caption, rounded corners, or a wrapper you can lay out, use a [data-media] ratio box. Its child iframe fills the box. On a <figure> with a <figcaption>, the ratio moves to the iframe and the caption flows below it (see figure).

Legacy .embed-responsive wrapper

The .embed-responsive class works the same way as [data-media] and accepts ratio modifier classes. Prefer data-ratio for new markup.

Wrapper ClassAspect RatioUse Case
.embed-responsive16:9YouTube, Vimeo, most video
.ratio-4x34:3Classic presentations, some maps
.ratio-1x11:1Square widgets
.ratio-21x921:9Cinematic video, ultrawide content

Live Embeds

Real-world embed examples showing YouTube video and OpenStreetMap.

Privacy note: Use youtube-nocookie.com instead of youtube.com for privacy-enhanced mode that doesn't set tracking cookies until the user plays the video.

Attributes

AttributePurpose
titleAccessible name. Required (see Accessibility).
srcURL of the embedded document.
srcdocInline HTML to render instead of src (wins when both are set). Pair with sandbox for untrusted markup.
width, heightInteger CSS pixels. The fallback size, and the preferred width with data-ratio.
allowPermissions Policy for the frame (see below).
sandboxRestricts what the framed document can do (see Security).
loadinglazy defers loading until the frame nears the viewport (see Performance).
referrerpolicyHow much of your URL is sent to the embedded site, e.g. no-referrer or strict-origin-when-cross-origin.
credentiallessLoads the frame in a fresh, ephemeral context without your cookies or storage, so third-party embeds work on pages with cross-origin isolation (COEP). Chromium only at present; other browsers ignore it.
nameBrowsing-context name, a target for <a target> and <form target>.
data-ratioVB: proportional sizing (see above).
data-mockVB prototyping: an iframe with no src gets a labelled placeholder via srcdoc. See data-mock.

The allow attribute (Permissions Policy)

allow takes a semicolon-separated list of features the framed document may use. Each feature defaults to the frame's own origin (src); add an origin list or * to widen it.

Use allow="fullscreen" rather than the legacy allowfullscreen attribute. Both work today; allowfullscreen is the older boolean form (equivalent to allow="fullscreen *"), and when allow also names fullscreen the allow value takes precedence. Keep to one vocabulary.

Security

The sandbox Attribute

Restricts iframe capabilities. Start with an empty value (most restrictive) and add tokens only as needed.

Never combine allow-scripts and allow-same-origin for content from your own origin. A same-origin document that may run scripts can reach into its parent, remove the sandbox attribute from its own iframe and reload itself unsandboxed: the sandbox is no protection at all. The pair is only meaningful for a cross-origin src, where the same-origin policy still separates the frame from your page. For untrusted HTML, use srcdoc or a separate origin with sandbox="allow-scripts" alone.
Sandbox TokenAllows
allow-scriptsJavaScript execution
allow-same-originKeep the document's real origin (cookies, storage, same-origin DOM access). Without it the frame gets an opaque origin.
allow-formsForm submission
allow-popupsOpen new windows/tabs (window.open, target="_blank")
allow-popups-to-escape-sandboxPopups open without inheriting the sandbox (needed for links out to normal sites)
allow-modalsalert(), confirm(), prompt(), print()
allow-downloadsDownloading files
allow-top-navigationNavigate the top-level page at any time
allow-top-navigation-by-user-activationNavigate the top-level page only after a user click (prefer this to allow-top-navigation)
allow-top-navigation-to-custom-protocolsOpen mailto:, tel: and other non-HTTP links in the top-level page
allow-presentationStart a Presentation API session (casting)
allow-orientation-lockLock screen orientation
allow-pointer-lockPointer Lock API (games, 3D viewers)
allow-storage-access-by-user-activationRequest unpartitioned storage via the Storage Access API

Content Security Policy

List exactly the origins you embed. The privacy-enhanced YouTube host is www.youtube-nocookie.com, not www.youtube.com.

To control who may frame your pages, send Content-Security-Policy: frame-ancestors from the embedded site; it can't be set from a meta tag.

Referrer Policy

Performance

Lazy Loading

Defer loading of below-the-fold iframes. Third-party embeds often pull in megabytes of script, so this is one of the cheapest wins on a page. Don't lazy-load an embed that is visible on first paint.

Give lazy iframes a size (width/height or data-ratio) so the space is reserved and nothing shifts when they load.

Printing

Browsers print only the visible part of an iframe, cropped to its box; scrolled-away content and video are lost. If the embedded content matters on paper, follow the frame with a link or summary that prints instead.

See Printing for how VB prints embedded media.

Accessibility

Title Attribute

Every iframe must have a title attribute that describes its content for screen readers.

Best Practices

  • Always provide a descriptive title attribute
  • Ensure embedded content is itself accessible; you can't fix it from the parent page
  • Provide alternative content (a link, transcript or summary) for critical information
  • Consider that some users block third-party content
  • Don't put tabindex="-1" on an interactive embed; keyboard users need to reach its controls

CSS Reference

Styles defined in /src/native-elements/iframe/styles.css and /src/utils/media.css.

SelectorProperties
iframedisplay: block; border: none; max-inline-size: 100%;
iframe.fullinline-size: 100%; (block size from height)
iframe.fixedinline-size: 100%; block-size: 400px;
iframe.roundedborder-radius: var(--radius-m); overflow: hidden;
iframe.borderedborder; border-radius;
:is(iframe, embed, object)[data-ratio]block-size: auto; aspect-ratio: var(--_ratio, 16 / 9); plus inline-size: 100% when there is no width attribute
[data-media] > iframeposition: absolute; inset: 0; 100% width/height
.embed-responsiveposition: relative; inline-size: 100%; aspect-ratio: 16 / 9;
.embed-responsive > :is(iframe, embed, object)position: absolute; inset: 0; 100% width/height

Related

  • <video> — For self-hosted video content
  • <audio> — For self-hosted audio content
  • <dialog> — For modal content on your own page
  • <object> — Legacy embed mechanism, PDF fallback
  • <embed> — Same data-ratio sizing
  • <figure> — Wrap embeds that need captions
  • data-mock — Placeholder iframes for prototypes
  • sandbox — Lock down what an iframe may do
  • srcdoc — Inline HTML documents for iframes
  • allow — Permissions Policy for iframes
↑