HTML Iframes

HTML Iframes
1. What Is an Iframe?
<iframe>= inline frameDisplays another HTML page within a page
Common uses: YouTube videos, Google Maps, ads, dashboards
2. Basic Iframe Example
Loads example.com inside your page
3. Iframe Attributes (Important)
| Attribute | Description |
|---|---|
src | URL of the page |
width | Width of iframe |
height | Height of iframe |
title | Accessibility (required) |
loading | Lazy loading |
allow | Permissions |
sandbox | Security restrictions |
4. Iframe with Title (Best Practice )
Improves accessibility
5. Embedding YouTube Video (Very Common)
Official YouTube embed format
6. Embedding Google Maps
7. Responsive Iframe (CSS Trick)
Works perfectly on mobile
8. Iframe Security – sandbox Attribute (Important)
With permissions:
- Prevents malicious behavior
- Very important for third-party content
9. Lazy Loading Iframes (Performance)
Loads iframe only when visible
Common Mistakes
- Missing
titleattribute - Using iframe for main page layout
- Embedding sites that block iframes
- Forgetting responsive design
Key Points to Remember
<iframe>embeds external contentAlways add
titleUse
loading="lazy"for performanceUse
sandboxfor securityMake iframes responsive for mobile
