HTML Iframes
What if your page could display another page inside it? Discover how iframes work, how to embed useful content, and how to keep those embedded experiences safe and accessible.
<iframe
title="Welcome"
srcdoc="<h2>Hello!</h2>"
></iframe>
A Web Page Inside Another Web Page?
Imagine you’re creating a travel guide and want to include a map, or you’re building a portfolio and want to display a video. You don’t have to recreate that content yourself.
An iframe (inline frame) embeds a separate HTML document inside your page. The embedded document has its own content, styles, and browsing context.
Meet the <iframe> Element
The most familiar way to embed a page is with the src attribute, which points to the document you want to display.
<iframe
src="https://example.com/"
title="Example website"
width="600"
height="300"
></iframe>
Here’s what those attributes do:
srcidentifies the document to load.titledescribes the embedded content for accessibility.widthandheightprovide initial dimensions.
Use srcdoc to Create Embedded Content
Here’s a fun trick: you can create an embedded document directly inside an iframe using srcdoc, without linking to another website.
<iframe
title="My welcome card"
sandbox
srcdoc="<h2>Welcome!</h2>
<p>I'm inside an iframe.</p>"
></iframe>
Nice Work!
You've learned how to embed separate documents, build your own content gallery, and think about security, accessibility, and responsive design. Another awesome skill unlocked!


