Skip to content
Learn Netverks

Lesson

Step 25/58 43% through track

iframes

Iframes

Last reviewed Jun 1, 2026 Content v20260601
Track mode
iframe_html
Means
HTML preview sandbox
Reading
~2 min
Level
advanced

This lesson

This lesson teaches Iframes—the ideas, syntax, and habits you need before moving on in HTML.

Without a solid grasp of Iframes, you will repeat mistakes in HTML exercises and on real pages or scripts.

You will apply Iframes in contexts like: Websites, hybrid apps, email templates, design systems, and CMS-driven content.

Read the lesson, edit HTML/CSS in the playground, press Run to preview, then answer the lesson MCQs. Also use the HTML reference desk when you need tag or attribute lookup.

When intermediate lessons feel comfortable and you are ready for production-style trade-offs.

<iframe> embeds another HTML document with its own window object, cookies, and execution environment—think maps, chat widgets, PDF viewers, or isolated demos.

Essential attributes

  • src: nested document URL.
  • title: accessible description for screen readers.
  • sandbox: strips capabilities unless explicitly allowed.
  • allow: delegates powerful APIs (camera, fullscreen).
  • loading="lazy": defer offscreen iframes.

Security

  • Third-party iframes execute scripts—audit vendors and use CSP.
  • sandbox tokens like allow-scripts allow-same-origin must be justified—combining both can escape sandbox mitigations.

Privacy & performance

  • Embedded players load large scripts—lazy load below the fold.
  • Provide privacy-enhanced domains when regulations demand.

Operational blind spots

  • Missing title on iframes—WCAG violations and confusing tab lists.
  • Infinite scroll inside iframes—focus traps escaping parent document are painful; test Tab cycles.
  • Payment or PII widgets—verify CSP + sandbox tokens with security, not marketers’ embed snippets blindly.

Live demo — srcdoc + strict sandbox

No src URL—HTML is inline-escaped. Scripts are blocked unless you add allow-scripts (add carefully).

Important interview questions and answers

  1. Q: What is the practical difference between `id` and `class`?
    A: `id` must be unique and is used for fragments/labeling; `class` is reusable for styling and behavior grouping.
  2. Q: Why is `defer` commonly preferred for scripts?
    A: It preserves HTML parsing, executes after parse, and avoids blocking rendering unlike classic synchronous scripts.
  3. Q: How do `srcset` and `sizes` work together?
    A: `srcset` provides candidate files and `sizes` tells expected rendered width so the browser can pick an optimal resource.

Pitfall: Sandboxed third-party iframes still need title attributes for accessibility.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Community stories on this track

Learner essays linked to HTML — not official lesson content.

Browse all stories

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What confused you about this lesson?
  • How would you explain this to a teammate in 30 seconds?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump