The <iframe> tag in HTML is used to embed another HTML document (webpage) within the current page. It essentially creates a “window” to another web page inside your page.
Key Uses of <iframe>
- Embedding external websites
- Example: You can display a YouTube video or Google Map.
- Embedding internal pages
- Load a different part of your own site inside a section without navigating away.
- Sandboxing content
- Restrict scripts or styles in the embedded content from affecting the parent page.
Basic Example
<iframe src="https://www.example.com" width="600" height="400" title="Example Site"></iframe>
src→ URL of the page to embedwidth/height→ size of the iframetitle→ accessibility, describes the content
Additional Attributes
sandbox→ restrict scripts, forms, and plugins inside iframeallowfullscreen→ enable full-screen modeloading="lazy"→ lazy-load iframe to improve performance
Example with sandbox:
<iframe src="https://www.example.com" width="600" height="400" sandbox></iframe>
💡 In Short:
<iframe>is used to embed external or internal web content within a page, useful for videos, maps, and other interactive content, while keeping it isolated from the main page.