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.
Video Generator Options
The interactive generator supports these controls:
- Source (MP4) sets the URL or relative path used by the child
<source>element. - Preload adds
auto,metadata, ornoneas a loading hint for the browser. - Width and Height set the video playback area’s dimensions in CSS pixels when values are provided.
- Autoplay, Controls, Loop, and Muted add the corresponding boolean attributes to the
<video>element.
The preview can play only a video resource that the browser can reach and decode. A relative source is resolved against the generator page URL.
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:
- Create an
HTMLDocumentand a<video>element withDocument.CreateElement(). - Apply the selected loading, playback, and dimension values with
Element.SetAttribute(). - Create a
<source>element for the MP4 resource and add it to the video withNode.AppendChild(). - Append the video to the document body and save
video.htmlwithHTMLDocument.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.
Related HTML Generators
Create other HTML structures and elements with focused generators: