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.
iFrame Generator Options
The interactive generator supports these controls:
- URL, Title, and Name identify the embedded HTTP or HTTPS page and its frame.
- Width, Height, and Border control the iframe through CSS using pixels or percentages.
- Lazy loading can defer an off-screen iframe; Sandbox applies browser restrictions.
- Allow and Referrer configure Permissions Policy features and referrer information.
The preview and both code panels update automatically. Invalid URLs use about:blank, and a remote website can still refuse iframe embedding through its response headers.
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:
- Create an
HTMLDocumentand anHTMLIFrameElement. - Set
Src,Title, and the optionalName, then apply dimensions and border throughICSSStyleDeclaration.SetProperty(). - Add the selected
loading,sandbox,allow, andreferrerpolicyvalues withElement.SetAttribute(). - Append the iframe to the document body and save
iframe.htmlwithHTMLDocument.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.
Related HTML Generators
Create other HTML structures and elements with focused generators: