HTML & CSS Interview Question #49

What is an iframe and what security considerations apply?

Forms, Validation, Metadata, Media, Responsive Images & Accessibility Mid-Level Intermediate

Quick Interview Answer

An iframe embeds another browsing context inside the current page. It can be used for content such as maps, videos, documents, or isolated applications.

Detailed Explanation

An iframe embeds another browsing context inside the current page. It can be used for content such as maps, videos, documents, or isolated applications.

Embedded content introduces security, privacy, performance, and accessibility considerations. Use a meaningful title, restrict capabilities with sandbox when appropriate, define permissions deliberately, and avoid embedding untrusted content with more privileges than it requires.

Code Example

<iframe
    src="https://example.com/embed/report"
    title="Monthly sales report"
    loading="lazy"
    sandbox="allow-scripts allow-same-origin">
</iframe>