Iframes and Embeds
What Is It?
An iframe shows another HTML document inside your page.
What the Tags Mean
iframe: the embedded document.src: the document’s path.srcdoc: HTML written directly in the attribute.title: explains the frame to assistive tools.sandbox: limits what the frame can do.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Iframes and Embeds</title>
</head>
<body>
<iframe title="Small welcome page" srcdoc="<h1>Hello!</h1><p>This is inside a frame.</p>" sandbox></iframe>
</body>
</html>Browser preview
What you see: You see a small separate page with Hello! and a sentence.
Example 2: Another Use
Use srcdoc to include a small timetable without creating a second file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Iframes and Embeds</title>
</head>
<body>
<iframe title="Class timetable" srcdoc="<h1>Timetable</h1><p>Saturday at 10 am.</p>" sandbox></iframe>
</body>
</html>Browser preview
Simple Tip
Use src when you have a separate file, such as timetable.html. Use srcdoc for included HTML. Always give the frame a useful title.
Try It Yourself
Change the text in srcdoc.