Create an HTML <table> Element Online
The HTML Table Generator creates table markup from the rows, columns, header, border, width, and alignment settings you select. The preview, HTML output, and C# output update together, so you can inspect the result before copying it into a webpage or .NET project.
Table Generator Options
The interactive generator supports these controls:
- Rows and columns set the table body size; Header row adds a separate
<thead>. - Border controls the style, width, and color of the table outline and cell grid.
- Width accepts percentages or pixels, while Alignment positions a table that is narrower than its container.
The preview and both code panels update automatically. HTML cells use blank placeholders; C# cells receive row and column labels.
Create an HTML <table> Element in C#
The HTML Code panel above contains the table markup produced from the current options. The C# Code panel below shows the equivalent programmatic workflow with Aspose.HTML for .NET .
The generated code follows this workflow:
- Create an
HTMLDocumentand a<table>element withDocument.CreateElement(). - Apply the selected border, width, and alignment settings through
ICSSStyleDeclaration.SetProperty(). - Add the optional header row, body rows, and cells with
HTMLTableSectionElement.InsertRow()and the corresponding row operations. - Append the table to the document body and save
table.htmlwithHTMLDocument.Save().
Configure the table first, then copy the updated code into your .NET project.
HTML Table Generator FAQ
1. Should I set the table width in percent or pixels?
Use percent when the table should adapt to the width of its parent container. Use pixels when you need a fixed table width that does not change with the surrounding layout.
2. Why does changing the table alignment sometimes have no visible effect?
Left, center, and right alignment use the free horizontal space around the table. If the table width fills its container, there is no remaining space in which to move it. Reduce the width to make the selected alignment visible.
3. Why is the table border not visible in the preview?
The border is not visible when its width is 0 or its style is none or hidden. Select a visible style such as solid, dashed, or dotted and set a border width greater than zero.
4. How large a table can I create with the generator?
You can generate from 1 to 100 body rows and from 1 to 100 columns. If Header row is enabled, the generator adds a separate header above the selected number of body rows.
5. Can I add the generated table to an existing HTML document?
Yes. Replace the parameterless HTMLDocument constructor with new HTMLDocument("input.html"), then append the generated table to the document body or another selected element and save the modified document to a new file.
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: