Iframe

Struct Iframe 

Source
pub struct Iframe;
Expand description

The <iframe> element - embeds another HTML page within the current page.

§Purpose

The <iframe> element represents a nested browsing context, embedding another HTML page into the current document. Creates an isolated environment for displaying external content, third-party widgets, or sandboxed applications with controlled permissions and communication.

§Content Categories

  • Flow Content
  • Phrasing Content
  • Embedded Content
  • Interactive Content
  • Palpable Content

§Permitted Content Model

  • Nothing (fallback text for browsers that don’t support iframes)

§Common Use Cases

  • Embedding third-party content (maps, videos, social media)
  • Displaying external widgets and plugins
  • Creating sandboxed environments for untrusted content
  • Loading advertisements in isolated contexts
  • Embedding interactive tools and applications

§Key Attributes

  • src: URL of the page to embed
  • srcdoc: Inline HTML content to display
  • name: Name for targeting the iframe
  • sandbox: Security restrictions (empty or space-separated tokens)
  • allow: Permissions policy (features the iframe can use)
  • width: Width in CSS pixels
  • height: Height in CSS pixels
  • loading: Lazy loading (“lazy” or “eager”)
  • referrerpolicy: Referrer policy for requests
  • allowfullscreen: Allow fullscreen mode
  • allowpaymentrequest: Allow Payment Request API

§Example

<!-- Basic iframe embedding -->
<iframe src="https://example.com/widget" width="600" height="400">
  Your browser doesn't support iframes.
</iframe>

<!-- Sandboxed iframe with restrictions -->
<iframe src="/untrusted.html"
        sandbox="allow-scripts allow-same-origin"
        width="100%" height="300">
</iframe>

<!-- Lazy-loaded iframe -->
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
        width="560" height="315"
        loading="lazy"
        allowfullscreen>
</iframe>

<!-- Iframe with inline content -->
<iframe srcdoc="<h1>Hello World</h1><p>This is inline HTML content.</p>"
        width="400" height="200">
</iframe>

<!-- Iframe with permissions policy -->
<iframe src="/map.html"
        allow="geolocation 'self'; camera 'none'"
        width="800" height="600">
</iframe>

§Accessibility

  • Provide a descriptive title attribute for screen readers
  • Ensure iframe content is keyboard accessible
  • Consider whether iframe content should be directly in the page instead
  • Test that embedded content meets accessibility standards
  • Ensure iframe has meaningful fallback text

§WHATWG Specification

Trait Implementations§

Source§

impl HtmlElement for Iframe

Source§

const TAG: &'static str = "iframe"

The HTML tag name (e.g., “div”, “span”, “img”).
Source§

const VOID: bool = false

Whether this is a void element (self-closing, no children allowed).
Source§

impl<T: FlowContent> CanContain<T> for Iframe

Source§

impl EmbeddedContent for Iframe

Source§

impl FlowContent for Iframe

Source§

impl InteractiveContent for Iframe

Source§

impl PalpableContent for Iframe

Source§

impl PhrasingContent for Iframe

Auto Trait Implementations§

§

impl Freeze for Iframe

§

impl RefUnwindSafe for Iframe

§

impl Send for Iframe

§

impl Sync for Iframe

§

impl Unpin for Iframe

§

impl UnwindSafe for Iframe

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.