Week 7: Meaningful Structure and Media
Learn to structure pages semantically and embed audio, video, and other content.
Explore Chapter 7Embedding Other Content (<iframe>)
An `<iframe>` (Inline Frame) is used to embed another HTML document within the current one. This is commonly used for embedding maps, videos from third-party sites (like YouTube), advertisements, or other external content.
<!-- Embedding a YouTube Video -->
<iframe width="560" height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
<!-- Embedding a Google Map -->
<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d..."
width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy">
</iframe>
Key Attributes of <iframe>:
- `src`: Specifies the URL of the page to embed.
- `width` / `height`: Define the dimensions of the frame (CSS is often preferred).
- `title`: Provides a description of the frame's content for accessibility. Important!
- `frameborder`: (Deprecated, use CSS `border` instead) Specifies whether to display a border around the iframe (0 = no border, 1 = border).
- `allow`: Specifies a feature policy for the iframe (e.g., what browser features it can access like camera, microphone, fullscreen).
- `allowfullscreen`: A boolean attribute that allows the iframe content to go fullscreen.
- `loading="lazy"`: A modern attribute that suggests the browser should defer loading the iframe until it's close to the viewport, improving initial page load performance.
Be cautious when embedding content from untrusted sources using iframes, as it can pose security risks.