Create an HTML <video> Element Online

The HTML Video Generator creates a <video> element with an MP4 <source>. Enter the video location, choose its loading and playback settings, and optionally set the playback area. The preview, HTML output, and C# output update together.



Create an HTML <video> Element in C#

The HTML Code panel above contains the configured <video> markup. The C# Code panel below creates the same element and MP4 source with Aspose.HTML for .NET .

The generated code follows this workflow:

  1. Create an HTMLDocument and a <video> element with Document.CreateElement() .
  2. Apply the selected loading, playback, and dimension values with Element.SetAttribute() .
  3. Create a <source> element for the MP4 resource and add it to the video with Node.AppendChild() .
  4. Append the video to the document body and save video.html with HTMLDocument.Save() .

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


HTML Video Generator FAQ

1. Why does the video not play in the preview?

The MP4 URL or relative path must resolve to a resource that the browser can access, and the browser must support the codecs stored in that MP4 container. Check the resolved URL, server response, and codec compatibility if the player remains empty or reports an unsupported source.

2. Why does an autoplay video remain paused?

Browsers commonly block autoplay when a video contains audible sound. Enable Muted when autoplay is required, but remember that browser policy and user preferences can still prevent automatic playback.

3. Does the preload option guarantee how much video the browser downloads?

No. The preload attribute is a browser hint. none discourages preloading, metadata requests basic media information, and auto allows more data to be fetched, but the browser may choose differently because of autoplay, network conditions, or data-saving settings.

4. What happens if the selected width and height have a different aspect ratio from the video?

Width and height define the playback area. Browsers normally preserve the media’s intrinsic aspect ratio inside that area, which can produce empty space at the sides or at the top and bottom. Leave one or both dimensions empty when fixed dimensions are unnecessary.

5. Does the generator upload, host, or convert the MP4 file?

No. The generator creates HTML and C# code that references the source you enter. The video file must already be available at that URL or relative path, and its encoding must be suitable for the browsers you intend to support.


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.