4 min read · Free · No login needed
An iframe (inline frame) shows another web page inside your page, in a small window. It is how YouTube videos, Google Maps, and other embedded content appear on websites.
The tag is <iframe src="https://www.youtube.com/embed/VIDEO_ID" width="560" height="315"></iframe>. The src is the page to show; width and height set the size of the window.
An iframe loads a whole second page, so it slows your page down — use it only when you need it. Some websites refuse to be shown inside an iframe (they send a header that blocks it). And for security, an iframe can run scripts from the other site, so only embed content from sources you trust. You can limit what an embedded page may do with the sandbox attribute.
title attribute (for example, title="YouTube video player"). Screen readers announce it, so blind visitors know what the frame contains.An <iframe> is a window inside your page that shows another web page. The other page loads inside a rectangle on your page, and it works as if the visitor had opened it in its own tab. It is how YouTube videos, Google Maps, and payment pages are placed inside other websites.
| Attribute | Value | Description |
|---|---|---|
src | a web address | The page to show inside the frame. Required. |
width / height | pixels or % | The size of the frame on your page. |
title | text | Describes the frame for screen readers. Always add it. |
loading | lazy | Loads the frame only when the user scrolls near it. |
allowfullscreen | — | Lets the framed page go full screen (needed for videos). |
sandbox | — | Blocks scripts, forms, and popups inside the frame — extra safety. |
A YouTube video embedded the usual way looks like this:
<iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="YouTube video player" allowfullscreen></iframe>
loading="lazy" to iframes below the fold. A map or video the visitor has not scrolled to should not slow down the first paint of your page.title attribute — screen reader users then hear only "frame" with no idea what is inside.sandbox — the framed page can run scripts in your visitor's browser.<!DOCTYPE html> — tells the browser this is an HTML5 page, so it renders in standard mode.<h1>Watch Our Intro</h1> — the heading above the video, so visitors know what they are about to watch.<iframe ...> — the window that shows the YouTube page inside this page. The src is the video's embed address, and width="560" and height="315" set the size of the window.title="YouTube video player" — describes the frame for screen readers, so blind visitors know what is inside it.allowfullscreen — lets the visitor expand the video to fill the whole screen.<!DOCTYPE html>
<html>
<head>
<title>Iframes</title>
</head>
<body>
<h1>Watch Our Intro</h1>
<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" title="YouTube video player" frameborder="0" allowfullscreen></iframe>
</body>
</html>
Change the code below and press Run to see the result instantly. No file to save, no login needed.
The questions learners ask most about this lesson — read the question, then open it to see the answer.
It is a window inside your page that shows another web page, used for YouTube videos, Google Maps, and other embedded content.
Some websites send a header that blocks framing, so the browser shows a blank box; there is nothing wrong with your code.
A title attribute, so screen readers can announce what the frame contains.
AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.
Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.
Take the testPrefer watching? Video courses teach the same topics step by step.
Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.
Browse all coursesAsk about courses, website & more
Request human callback:
Please log in to download. You will stay on this page after logging in!
New here? Register now →