JNI Solutions HTML Library
A .NET library written in C# for programmatically generating and parsing HTML documents. The library provides a strongly-typed class for each supported HTML tag, making it easy to build well-structured HTML output without writing raw markup.
Features
- Create complete HTML documents programmatically
- Strongly-typed classes for all commonly used HTML tags
- Parse existing HTML documents back into an object model
- Full support for global HTML attributes and event attributes on every element
- Multi-target: runs on .NET Framework 4.8 and modern .NET
Supported .NET Versions
| Platform |
Versions |
| .NET Framework |
4.8 |
| .NET |
6.0, 8.0, 10.0 |
Note: .NET Framework 4.8 is supported on Windows only. .NET 6.0, 8.0, and 10.0 are supported on Windows, Linux, and macOS.
Document Structure
| Class |
HTML Tag |
Description |
HTMLDocument |
(full document) |
Represents a complete HTML document including <html>, <head>, and <body> |
HTMLHeadElement |
<head> |
Document head container — holds metadata tags |
HTMLBodyElement |
<body> |
Document body container — holds visible content |
| Class |
HTML Tag |
Description |
Base |
<base> |
Specifies a base URL and/or target for all relative links in the page |
Link |
<link> |
Links external resources such as stylesheets |
Meta |
<meta> |
Defines metadata such as charset, viewport, and Open Graph tags |
Style |
<style> |
Embeds an internal CSS style block |
Title |
<title> |
Sets the document title shown in the browser tab |
Sectioning & Grouping
| Class |
HTML Tag |
Description |
BlockQuote |
<blockquote> |
A section quoted from another source |
Div |
<div> |
Generic block-level container |
Hgroup |
<hgroup> |
Groups a heading with related content such as a subheading |
Nav |
<nav> |
A section of navigation links |
NoScript |
<noscript> |
Fallback content rendered when scripting is disabled |
Headings
| Class |
HTML Tag |
Description |
Heading |
<h1> – <h6> |
Section headings — level 1 (most important) to level 6 |
Text Content
| Class |
HTML Tag |
Description |
Address |
<a> |
Hyperlink (anchor tag) |
Abbr |
<abbr> |
Abbreviation or acronym with an expanded title |
Para |
<p> |
Paragraph |
Pre |
<pre> |
Preformatted text, preserving whitespace and line breaks |
Text |
(text node) |
Plain text content — no surrounding tag |
Inline Text Formatting
| Class |
HTML Tag |
Description |
Bold |
<b> |
Bold text |
Emphasis |
<em> |
Emphasised (italic) text |
Italic |
<i> |
Italic text |
SpanT |
<span> |
Generic inline container |
Strong |
<strong> |
Strong importance (bold) text |
Lists
| Class |
HTML Tag |
Description |
DD |
<dd> |
Description / definition in a definition list |
DL |
<dl> |
Definition list |
DT |
<dt> |
Term in a definition list |
LI |
<li> |
List item in an ordered or unordered list |
OL |
<ol> |
Ordered (numbered) list |
UL |
<ul> |
Unordered (bulleted) list |
Tables
| Class |
HTML Tag |
Description |
Caption |
<caption> |
Table caption |
Col |
<col> |
Column properties within a <colgroup> |
ColGroup |
<colgroup> |
Group of columns in a table |
DataCell |
<td> |
Table data cell |
HeaderCell |
<th> |
Table header cell |
Table |
<table> |
Table |
TableRow |
<tr> |
Table row |
Tbody |
<tbody> |
Table body section |
Tfoot |
<tfoot> |
Table footer section |
Thead |
<thead> |
Table header section |
Embedded Content
| Class |
HTML Tag |
Description |
Iframe |
<iframe> |
Inline frame embedding another HTML page |
Image |
<img> |
Embeds an image |
Object |
<object> |
Embeds external content such as a plugin or media file |
Param |
<param> |
Parameter for an <object> element |
| Class |
HTML Tag |
Description |
Button |
<button> |
Clickable button |
Scripting
| Class |
HTML Tag |
Description |
Script |
<script> |
Embeds or references client-side JavaScript |
Other
| Class |
HTML Tag |
Description |
BR |
<br> |
Line break |
Comment |
`` |
HTML comment |
HR |
<hr> |
Thematic break (horizontal rule) |
CSS Helpers
| Class |
Description |
CSSdeclaration |
Represents a single CSS property-value pair |
CSSselector |
Represents a complete CSS rule (selector + declarations) |
Getting Started
Installation
Install via NuGet:
dotnet add package JNIsolutions.Net.HTMLlib
Example
using JNIsolutions.Net.HTMLlib;
using System.Globalization;
// Create a new HTML document
HTMLDocument document = new HTMLDocument
{
Lang = CultureInfo.CurrentUICulture
};
// Add head elements
document.Head.Tags.Add(new Meta { Name = "viewport", Content = "width=device-width, initial-scale=1" });
document.Head.Tags.Add(new Title("My Page"));
document.Head.Tags.Add(new Link
{
Rel = "stylesheet",
Href = "https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
});
// Add body content
Hgroup hgroup = new Hgroup();
hgroup.Keywords.Add(new Heading("Welcome", 1));
hgroup.Keywords.Add(new Para("Hello, world!"));
document.Body.Tags.Add(hgroup);
// Build a table
Table table = new Table();
table.Keywords.Add(new Caption("People"));
Thead thead = new Thead();
TableRow headerRow = new TableRow();
headerRow.Keywords.Add(new HeaderCell("Name"));
headerRow.Keywords.Add(new HeaderCell("Age"));
thead.Keywords.Add(headerRow);
table.Keywords.Add(thead);
Tbody tbody = new Tbody();
TableRow dataRow = new TableRow();
dataRow.Keywords.Add(new DataCell("Alice"));
dataRow.Keywords.Add(new DataCell("30"));
tbody.Keywords.Add(dataRow);
table.Keywords.Add(tbody);
document.Body.Tags.Add(table);
// Render to HTML string
string html = document.ToString();
Console.WriteLine(html);
Parsing HTML
The library can also parse an existing HTML string back into an object model:
string existingHtml = File.ReadAllText("page.html");
HTMLDocument parsed = new HTMLDocument().Parse(existingHtml);
Console.WriteLine(parsed.ToString());
License
This project is licensed under the BSD 4-Clause License. See LICENSE.txt for details.