What is an iFrame?
An iFrame (inline frame) is used to embed another webpage or external content within the current HTML page.
Basic Syntax
HTMLRead-only
1
Common Attributes
| Attribute | Description |
|---|---|
| src | URL of the embedded page |
| width | Width of iframe |
| height | Height of iframe |
| title | Accessibility description |
| allowfullscreen | Enable fullscreen mode |
| loading | Lazy loading (lazy/eager) |
Embedding YouTube Video
HTMLRead-only
1
Embedding Google Map
HTMLRead-only
1
Inline Frame Example
HTMLRead-only
1
Security Considerations
iFrames can pose security risks. Use attributes like sandbox to restrict behavior and ensure content comes from trusted sources.
HTMLRead-only
1
Best Practices
- Always include title for accessibility
- Use trusted sources only
- Enable lazy loading for performance
- Use sandbox for security
- Avoid excessive use of iframes
Common Mistakes
- Embedding insecure or unknown sources
- Not setting dimensions properly
- Ignoring accessibility (missing title)
- Overusing iframes affecting performance
Conclusion
HTML iFrames are powerful for embedding external content like videos and maps. Proper use ensures security, performance, and a smooth user experience.