HTML iframe Element
Subject: html
πͺ HTML <iframe>
Element
The <iframe>
(short for inline frame) is used to embed another HTML document or external resource such as a webpage, video, map, or PDF within your current page. It acts like a window showing content from another location.
π§ Syntax
src
: URL of the content to displaywidth
andheight
: Dimensions of the frametitle
: Description for accessibility (required for screen readers)loading
: Set tolazy
for performance optimizationallowfullscreen
: Enables full-screen mode for media contentstyle
: Internal CSS stylingframeborder
: Deprecated (use CSS instead)
β Basic Iframe Example
π¨ Styled Iframe with Internal CSS
πΊ Embedding a YouTube Video
πΊοΈ Embedding a Google Map
π‘οΈ Security and Performance Tips
- Use
sandbox
attribute to restrict iframe actions:
- Use
loading="lazy"
to defer off-screen content loading - Avoid mixed content (HTTP inside HTTPS pages)
- Donβt embed content from untrusted sources
π Common Use Cases
- Embedding YouTube videos
- Displaying Google Maps
- Embedding PDFs or Slides
- Loading another webpage
π§ Key Takeaways
<iframe>
embeds external or internal pages into the current HTML document- Always include
title
for accessibility - Use
sandbox
,loading
, and CSS for control, performance, and design - Use responsibly to avoid performance issues or security risks
Advertisement Slot 1
Advertisement Slot 2