Create an HTML iFrame Online

The iFrame Generator creates an <iframe> element for embedding an HTTP or HTTPS page. Set the source URL, descriptive title, dimensions, border, loading behavior, sandbox restrictions, allowed browser features, and referrer policy, then inspect the preview and copy the generated HTML or C# code.



Create an HTML iFrame in C#

The HTML Code panel above contains the configured <iframe> markup. The C# Code panel below creates an equivalent element with Aspose.HTML for .NET .

The generated code follows this workflow:

  1. Create an HTMLDocument and an HTMLIFrameElement .
  2. Set Src, Title, and the optional Name, then apply dimensions and border through ICSSStyleDeclaration.SetProperty() .
  3. Add the selected loading, sandbox, allow, and referrerpolicy values with Element.SetAttribute() .
  4. Append the iframe to the document body and save iframe.html with HTMLDocument.Save() .

Configure the iframe first, then copy the updated C# code into your .NET project.


HTML iFrame Generator FAQ

1. Why does a website appear blank or refuse to load in the iframe preview?

The website may block framing with an X-Frame-Options header or a Content Security Policy frame-ancestors directive. Generated HTML and C# code cannot override the remote server’s policy; use a URL whose owner permits embedding.

2. Why does a percentage height produce an unexpected result?

A percentage height depends on the computed height of the iframe’s containing block. If the parent does not have a definite height, use pixels or define an explicit height for the parent container.

3. What is the difference between Sandbox restrictions and Allow?

The sandbox attribute restricts capabilities of the embedded page, while allow grants selected browser features through Permissions Policy. Grant only the capabilities the embedded content requires; an allow value does not remove sandbox restrictions.

4. Which referrer policy should I choose for an iframe?

Use the browser default unless the embedded service requires a specific policy. Choose no-referrer to send no referrer information, or strict-origin-when-cross-origin to send the full URL on same-origin requests and only the origin on secure cross-origin requests.

5. Why does the generator replace my iframe URL with about:blank?

The preview accepts only valid HTTP and HTTPS URLs. Empty, malformed, or potentially executable schemes are replaced with about:blank so they cannot run as an iframe source in the generator preview.


Get Started with Aspose.HTML for .NET API

Install Aspose.HTML for .NET from NuGet with the .NET CLI:

dotnet add package Aspose.HTML

You can also use the NuGet Package Manager UI or run Install-Package Aspose.HTML in the Package Manager Console. See the installation guide for setup details, or request a temporary license to evaluate the API without evaluation limitations.