October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Embed a Webpage Within Another Webpage with HTML

Use an HTML iframe to display another webpage. Learn how to set its URL, title and dimensions, and what to check when the destination blocks framing.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use an HTML <iframe> to display an existing webpage inside another webpage. Set its src to the page’s URL, give the frame a descriptive title, and choose dimensions that work in your layout. The destination site must also permit framing; the iframe code alone cannot override its restrictions.

Embed a webpage with an iframe

An <iframe> creates a nested browsing context: the outer page contains a separate document loaded from the URL in the iframe’s src attribute. For a basic example, replace the sample URL with the page you want to display:

As an Amazon Associate I earn from qualifying purchases.

<iframe
  src="https://example.com"
  title="Example service page"
  width="600"
  height="400"
  loading="lazy">
</iframe>

The example URL and dimensions are illustrative, not required values. Include both the opening and closing iframe tags. The title should briefly describe what the embedded page contains, so people using screen readers can identify the frame without first entering it. MDN’s iframe reference recommends this kind of concise label.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Make the frame fit the page

The width and height attributes specify dimensions in CSS pixels. CSS can override them. A fluid width is useful when the containing layout changes size:

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
iframe {
  display: block;
  width: 100%;
  max-width: 100%;
  border: 0;
}

This makes the iframe element fit its parent’s width, but it does not make the frame automatically match the height of an arbitrary remote page. The embedded document does not normally provide its dimensions to the parent for responsive sizing. Choose a suitable height, or use a sizing arrangement supported by the embedded page.

Check whether the destination allows embedding

A syntactically correct iframe does not guarantee that the destination will appear. The remote site can use security policies that refuse to be displayed in a frame. If the frame is blank or reports that it was refused, check the destination’s current embedding instructions and security policy. The restriction belongs to the site being embedded; changing your page’s CSS will not remove it. MDN’s iframe reference and MDN’s guide to embedded content describe the relevant embedding behavior.

Know what the outer page can control

The iframe is a separate document. CSS on the outer page can style the iframe element—such as its size and border—but does not give the outer page permission to restyle an unrelated website inside it. Likewise, browser same-origin protections restrict scripts from reading or changing a cross-origin document’s contents. If both pages need to exchange data, they must implement a supported communication method such as postMessage().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use sandbox restrictions carefully

The sandbox attribute can restrict capabilities available to the embedded page. Add only the permissions the embedded application needs, using individual tokens where appropriate. Restrictions can affect scripts, forms, and popups, so verify required interactions after adding a sandbox.

MDN warns that combining allow-scripts and allow-same-origin for same-origin embedded content can undermine the sandbox. Review the iframe attribute reference before choosing permissions; a broad sandbox is not automatically safer if it breaks the required behavior or is configured to negate its protections.

Defer offscreen frames when appropriate

An iframe loads a separate document environment and adds memory and computing work. For a frame that is initially offscreen, loading="lazy" can defer loading and reduce work during the initial page load. MDN notes that lazy loading applies when JavaScript is enabled. Do not defer a frame that must be immediately visible or usable.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

When to use another element

For embedding an entire webpage, use <iframe>. The similarly named <object> and <embed> elements serve other embedded-resource use cases; they are not general replacements for an iframe when the goal is to show another web document. See MDN’s embedded content guide for the distinction.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What about adding audio?

Audio is a separate task, not a webpage-embedding method. Use the HTML <audio> element when you want to add playable audio content to a page.

Why the older forum answer still needs context

A SitePoint Forums question from July 12, 2016 asked how to embed a webpage and how to add audio. A reply recommended an iframe for the webpage, which remains the right element for embedding a whole document. The thread also contains a dated disagreement about whether <object> replaces an iframe; current MDN guidance distinguishes the elements by their use rather than treating them as interchangeable. The original thread is available at SitePoint Forums.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.