Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

iframe — embedded document

The iframe element embeds a separate document. Learn how src differs from srcdoc and how sandbox restricts content.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<iframe src="URL" title="Description"></iframe>
<iframe srcdoc="HTML" title="Description" sandbox></iframe>

iframe embeds a separate HTML document. src specifies a URL, whereas srcdoc contains HTML and takes precedence over src. Both tags are required; content between them is not the embedded document.

An empty sandbox enables restrictions, including blocking script execution and form submission. Forms can still render, and users can still interact with their controls. Tokens relax selected restrictions. Do not combine allow-scripts and allow-same-origin for untrusted same-origin content: it can remove the protection. In the example, srcdoc supplies local content without network fetching.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>iframe demo</title>
<iframe title="Greeting" sandbox
        srcdoc="<p>Hello from iframe.</p>"></iframe>
</html>

Result

Hello from iframe.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources