CHAPTER 11
Beginner
HTML iframe and Embedding Content
Updated: May 10, 2026
5 min read
# HTML iframe and Embedding Content
1. Introduction
An<iframe> (Inline Frame) allows you to embed another HTML document inside your current HTML document. It's like cutting a rectangular window in your webpage to look at another webpage. We use this heavily for embedding YouTube videos and Google Maps.
2. Learning Objectives
-
Use the
<iframe>tag to embed external websites.
- Embed YouTube videos properly.
- Embed Google Maps.
- Understand basic security attributes.
3. Detailed Explanations
The <iframe> Basics
You specify the URL of the external page in the src attribute.
html
Removing the Border
By default, iframes have an ugly border. Use CSS or theframeborder attribute to remove it.
html
*Note: Always include a title attribute for accessibility so screen readers know what is in the iframe!*
Embedding YouTube Videos
YouTube makes this easy. Right-click any video and click "Copy embed code".
html
*Notice the allowfullscreen attribute? That lets the user expand the video to their whole monitor.*
Security: sandbox
If you are embedding a site you don't fully trust, you can restrict what the iframe can do (like preventing it from running JavaScript or opening popups) using the sandbox attribute.
html
4. Mini Project: Travel Info Card
Let's build a UI component that shows a destination and an embedded map!
html
5. MCQs
Q1: Which attribute is required to define the URL of the page you want to embed in an iframe? A) href B) link C) src D) url *Answer: C*6. Summary
iframes are powerful tools for bringing third-party services (Maps, YouTube, Spotify players) into your website without having to build them from scratch. Always remember to give your iframes atitle for accessibility!