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 embedsrcdoc: Inline HTML content to displayname: Name for targeting the iframesandbox: Security restrictions (empty or space-separated tokens)allow: Permissions policy (features the iframe can use)width: Width in CSS pixelsheight: Height in CSS pixelsloading: Lazy loading (“lazy” or “eager”)referrerpolicy: Referrer policy for requestsallowfullscreen: Allow fullscreen modeallowpaymentrequest: 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
titleattribute 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
impl HtmlElement for Iframe
impl<T: FlowContent> CanContain<T> for Iframe
impl EmbeddedContent for Iframe
impl FlowContent for Iframe
impl InteractiveContent for Iframe
impl PalpableContent for Iframe
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more