You might see <iframe> Element reference while reading someone else’s HTML, or need it while building a page of your own. Instead of memorizing a definition, look at a working example and see when the element makes sense.
The Idea in Plain English
Embeds another document in a nested browsing context. Name its purpose with title and consider sandbox and privacy restrictions.
For a reference page, pay attention to where the element is allowed, whether it needs a closing tag, and what other elements it can contain.
A Working Example
Read the sample once before copying it. Notice the element names and attribute values, then compare them with the explanation below.
<iframe src="/demos/graph.html"
title="Graph demonstration"
width="640" height="360"
loading="lazy"></iframe>
What Each Part Does
- An iframe embeds another page in a separate browsing context.
- src points to the asset the browser should load.
- title can provide supplementary information but is not a universal replacement for visible text.
- width reserves the image or embedded resource’s intended horizontal dimension.
An embedded page appears within a frame when the resource allows embedding.
Try It Yourself
Try replacing the example content with your own while keeping the valid HTML structure.
Common Beginner Mistakes
- Expecting to read cross-origin iframe content with ordinary DOM JavaScript.
- Changing several parts of the example at once, making it difficult to see which part caused a different result.
- Choosing a tag only because its default appearance looks right, without checking whether it describes the content correctly.
Key Takeaways
- Embeds another document in a nested browsing context. Name its purpose with title and consider sandbox and privacy restrictions.
- An embedded page appears within a frame when the resource allows embedding.
- Test the markup in a browser, and check accessibility and real-world behavior where relevant.