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. It's commonly used for third-party content like video players, maps, widgets, and external applications.
Vanilla Breeze removes default borders and provides responsive wrapper classes for common aspect ratios, ensuring embedded content scales properly across devices.
When to Use
- Video embeds - YouTube, Vimeo, and other video platforms
- Maps - Google Maps, OpenStreetMap embeds
- Social widgets - Twitter timelines, Facebook posts
- Payment forms - Stripe, PayPal checkout
- Third-party tools - Calendars, forms, surveys
When to Use Other Elements
Variants
Default
Basic iframe without borders.
.bordered
Adds subtle border and rounded corners.
.rounded
Medium border radius without border.
.full
Full container width.
.fixed
Full width with fixed height (400px).
Responsive Embeds
Use the .embed-responsive wrapper to maintain aspect ratio while filling available width.
.embed-responsive (16:9 default)
.ratio-4x3
.ratio-1x1
.ratio-21x9
| Wrapper Class | Aspect Ratio | Use Case |
|---|---|---|
.embed-responsive |
16:9 | YouTube, Vimeo, most video |
.ratio-4x3 |
4:3 | Classic presentations, some maps |
.ratio-1x1 |
1:1 | Instagram embeds, square widgets |
.ratio-21x9 |
21:9 | Cinematic video, ultrawide content |
Security Considerations
Iframes can pose security risks. Follow these best practices:
The sandbox Attribute
Restricts iframe capabilities. Start with an empty value (most restrictive) and add permissions as needed.
| Sandbox Value | Allows |
|---|---|
allow-scripts |
JavaScript execution |
allow-same-origin |
Treat content as same origin |
allow-forms |
Form submission |
allow-popups |
Open new windows/tabs |
allow-modals |
Modal dialogs (alert, confirm) |
allow-downloads |
Downloading files |
Content Security Policy
Control which sources can be embedded with the frame-src directive.
Referrer Policy
Control what information is sent to the embedded content.
Live Examples
YouTube Video
Google Maps
Vimeo Video
Accessibility
Title Attribute
Every iframe must have a title attribute that describes its content.
Loading Attribute
Defer loading of off-screen iframes for better performance.
Best Practices
- Always provide a descriptive
titleattribute - Use
loading="lazy"for below-the-fold embeds - Ensure embedded content is itself accessible
- Provide alternative content for critical information
- Consider that some users block third-party content
Related Elements
CSS Reference
Styles defined in /src/native-elements/iframe/styles.css
| Selector | Properties |
|---|---|
iframe |
display: block; border: none; max-inline-size: 100%; |
iframe.full |
inline-size: 100%; |
iframe.fixed |
block-size: 400px; |
iframe.rounded |
border-radius: var(--radius-m); overflow: hidden; |
iframe.bordered |
border; border-radius; |
.embed-responsive |
position: relative; aspect-ratio: 16 / 9; |
.embed-responsive > iframe |
position: absolute; inset: 0; 100% width/height; |