A noticeboard can have a small window showing a separate sheet. An iframe, meaning inline frame, provides a similar idea: one HTML document contains a viewing area for another document. The outer page and the inner page are separate documents.
Use a frame when you need an actual embedded document, such as a supported map or video service. To divide your own page into topics, use ordinary sections rather than several frames. A link is often simpler when readers do not need to see the second document inside the first.
Read the main attributes
Src is the address of the document to load. Title gives the frame a descriptive label, particularly useful to people navigating with assistive tools. Width and height reserve an area; integer HTML values represent CSS pixels. Close iframe with an explicit closing tag: it is not a void element.
HTML fragment — part of a document
<iframesrc="frame-note.html"title="Preparation note for the practice session"width="360"height="220"sandbox=""
></iframe>
The title does not replace the inner page's title or normally appear as a visible heading. Provide surrounding visible context too. Our CSS max-width rule lets the frame fit a narrow container; it does not automatically resize the inner document to its content height.
Save and test both files
Save frame-note.html and frame-host.html in the same folder. Open the host. Src uses a relative path from that host file. The note should appear inside the frame. If it does not, open the direct note link and check the folder and filename.
In this tutorial's isolated example preview, nested frames are deliberately not loaded. The preview shows a replacement explanation; save both complete files locally to see the embedding. Do not mistake that preview restriction for an error in the saved example.
Sandbox limits what the embedded document can do
The sandbox attribute applies restrictions to the frame. An empty value enables the restriction set, including blocking scripts, form submission and popups. The static note does not need those abilities. Sandbox does not by itself prevent every network request, so it is not a general no-internet switch.
Named permission tokens can relax particular restrictions. Do not add a collection of allow tokens merely to silence an error. In particular, combining allow-scripts and allow-same-origin for same-origin embedded content can defeat the intended isolation. Start with the capabilities the actual trusted content needs and check the resulting boundary.
Loading, referrers and outside services
Loading=lazy asks the browser to defer loading a frame until it is likely to be needed; it is not an exact download-time guarantee. Referrerpolicy=no-referrer tells it not to send a Referer request header for the embedded document fetch. It does not make the visitor anonymous to an outside service.
An external embed can still involve the provider receiving a request and using its own storage or cookies subject to browser policy. Avoid inserting third-party embeds by habit. Offer an ordinary link when that better serves readers.
Why a website can refuse embedding
The owner of another site can send security headers that disallow framing. A correct URL and title do not override that decision. Do not try to bypass it. Use the provider's documented embed address if available, or link to the page normally.
A browser also separates documents from different origins. An origin is roughly the combination of protocol, host and port. Your page cannot freely read another origin's frame content. Sandbox can impose more restrictions. Embedding a page is not permission to read or control everything inside it.
Other frame features to recognise
Name identifies a browsing target for links, while id identifies an element in the current document. A link target can match a frame name when that behaviour is deliberately wanted. Title has a different job: describing the frame to readers.
Srcdoc can supply an HTML string instead of a fetched source document. Quotes and ampersands must be escaped correctly inside the attribute, and it is unsafe to insert untrusted text as HTML without appropriate handling. Keep our beginner example in a separate file. Avoid obsolete frameborder, scrolling and frameset layouts; use CSS for presentation and normal HTML for page regions.
Follow the idea
Two documents, two roles
1Host page: surrounding explanation
2Src: the separate note address
3Title: describe the frame
4Sandbox: restrict its capabilities
Save both local files; nested frames are omitted in the isolated preview.
Complete program: frame-note.html
Save this as frame-note.html. Open it in your browser.
frame-note.html
<!doctype html><htmllang="en"><head><metacharset="UTF-8" /><metaname="viewport"content="width=device-width, initial-scale=1" /><title>A Small Embedded Note</title></head><body><h1>Before the practice session</h1><main><p>Bring a notebook and save one HTML example to discuss.</p><ul><li>Check the filename.</li><li>Open it in your browser.</li></ul></main></body></html>
Browser previewDocument title: A Small Embedded Note
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Expected result: the standalone preparation note, with its heading, sentence and two-item list. This is the inner document; it also works as a normal independent page.
Complete program: frame-host.html
Save this as frame-host.html. Open it in your browser.
frame-host.html
<!doctype html><htmllang="en"><head><metacharset="UTF-8" /><metaname="viewport"content="width=device-width, initial-scale=1" /><title>A Page Containing a Note</title><style>
iframe {
max-width: 100%;
border: 1px solid #777;
}
</style></head><body><h1>Read the note inside this page</h1><main><p>This page embeds a second local document. Save frame-note.html beside it.</p><iframesrc="frame-note.html"title="Preparation note for the practice session"width="360"height="220"loading="lazy"referrerpolicy="no-referrer"sandbox=""
></iframe><p><ahref="frame-note.html">Open the preparation note as a normal page</a></p></main></body></html>
Browser previewDocument title: A Page Containing a Note
This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here. Nested frames are not loaded in this preview. Save the host page and its note file together to test the embedded document locally.
Expected result in saved files: the preparation note appears inside a bordered frame, followed by a normal link to the same note. The nested frame is replaced with an explanation in this tutorial preview. No script, upload or external service is involved.
Problem and solution
Problem: a remote site stays blank inside an iframe although its URL opens normally.
Solution: first verify the URL and your own path. If the site refuses framing, respect its policy. Use a supported embed address or an ordinary link. Do not remove restrictions blindly.
Common mistakes and useful tips
Do not use iframe to create ordinary page columns.
Give every frame a useful title.
Keep a normal link available where useful.
Do not assume sandbox blocks every network request.
Do not use obsolete frameborder styling.
Test the saved pair of files, since nested embedding is unavailable in this preview.
Practice questions
How many documents are involved in the example?
What does src identify?
What does title provide?
What does sandbox="" do?
Can you force an unwilling site to permit framing?
Save the two files together and open the host, then open its direct note link. What changes?
Check your practice answers
Two: the host and the embedded note.
The document address to load.
A descriptive name for the frame, not the inner page's visible heading.
It enables the sandbox restrictions without permission tokens.
No. Use a permitted embed or link normally.
The same note is first inside the host's viewing area, then opened as its own page.
Interview questions
How is iframe different from div?
Iframe contains another document with its own document structure. Div groups content within the current document.
Is title the same as name?
No. Title describes the frame for readers. Name can identify its browsing target for links.
Why use a restrictive sandbox?
It limits abilities of embedded content. Grant only what the intended content needs; do not assume it blocks every kind of request.
Why might a correct external URL fail inside a frame?
The provider may disallow framing through its security headers, or the embed may need a different documented address. Linking normally can be the appropriate solution.