HTML iframe Tag
Learn how to use the HTML <iframe> tag to embed webpages, videos, and maps — covering src, height, width, name, srcdoc, allow, and security best practices.
- What is an iframe?
- Syntax
- Attribute Reference
- src Attribute
- height & width
- name Attribute
- srcdoc Attribute
- Security
- Try It Yourself
- Summary
- FAQ
What is an HTML iframe?
The HTML <iframe> tag stands for inline frame. It embeds another HTML document inside your current page — like a window within a window. Common uses include YouTube videos, Google Maps, social media widgets, and external web content.
iframe Syntax
<!-- Basic --> <iframe src="URL"></iframe> <!-- With size --> <iframe src="https://tipsinlearning.blogspot.com" width="600" height="400" title="TipsInLearning" style="border: none; border-radius: 12px;"> </iframe>
iframe Attribute Reference
The src Attribute
src — Embed a Webpage by URL
Specifies the URL of the webpage to embed. This is the only required attribute — without it the iframe shows nothing.
<!-- Embed TipsInLearning --> <iframe src="https://tipsinlearning.blogspot.com" width="100%" height="400" title="TipsInLearning Website"> </iframe> <!-- Embed a YouTube video --> <iframe src="https://www.youtube.com/embed/VIDEO_ID" width="560" height="315" title="YouTube video" allow="fullscreen" style="border: none;"> </iframe>
height and width
height / width — Set iframe Size
Use pixels or percentage. CSS style attribute also works — both approaches are valid.
<!-- Fixed pixel size --> <iframe src="https://tipsinlearning.blogspot.com" height="200" width="300"></iframe> <!-- Responsive: full width --> <iframe src="https://tipsinlearning.blogspot.com" style="width:100%;height:400px;border:none;border-radius:12px;"> </iframe>
The name Attribute
name — Use iframe as a Link Target
Give the iframe a name, then use that name as the target on a link — clicking the link loads the URL inside the iframe instead of a new tab.
<!-- The iframe with a name --> <iframe src="https://tipsinlearning.blogspot.com" name="myframe" height="400" width="100%"></iframe> <!-- These links load inside the iframe --> <a href="https://tipsinlearning.blogspot.com" target="myframe">Load HTML Course</a>
The srcdoc Attribute
srcdoc — Embed Inline HTML
Write HTML directly in the attribute — the iframe renders it without needing an external URL. When both src and srcdoc are present, srcdoc wins.
<iframe srcdoc="<html><body style='font-family:Arial;background:#f3eeff;padding:20px'> <h2 style='color:#7c3aed'>TipsInLearning</h2> <p>Free web development courses!</p> </body></html>" width="400" height="150"> </iframe>
Security Best Practices
<!-- sandbox: block everything --> <iframe src="https://example.com" sandbox></iframe> <!-- Allow only specific features --> <iframe src="https://example.com" sandbox="allow-scripts allow-same-origin"> </iframe> <!-- Production best practice --> <iframe src="https://tipsinlearning.blogspot.com" title="TipsInLearning HTML Course" loading="lazy" style="border:none;"> </iframe>
Try It Yourself
Questions Beginners Ask
Common questions about HTML iframes: