FluentHtmlStringBuilder 1.0.0

dotnet add package FluentHtmlStringBuilder --version 1.0.0
                    
NuGet\Install-Package FluentHtmlStringBuilder -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentHtmlStringBuilder" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentHtmlStringBuilder" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FluentHtmlStringBuilder" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentHtmlStringBuilder --version 1.0.0
                    
#r "nuget: FluentHtmlStringBuilder, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluentHtmlStringBuilder@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentHtmlStringBuilder&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FluentHtmlStringBuilder&version=1.0.0
                    
Install as a Cake Tool

FluentHtmlStringBuilder

A lightweight, fluent, strongly-typed API for building HTML markup in C#. Compose HTML elements as plain C# objects using chainable methods, then render the final markup with a single ToString() call — no template files and no manual string concatenation.

Features

  • Fluent, chainable API — every attribute setter returns the element itself, so calls compose naturally.
  • Strongly-typed elements for containers, text, forms, tables, lists, media, semantic layout, and interactive HTML tags.
  • Safe by defaultHtmlTextNode HTML-escapes text content automatically, while HtmlRawTextNode is available for trusted raw markup (e.g. inline <script>/<style> content).
  • Shared global & ARIA attributes (id, class, data-*, aria-*, style, title, tabindex, and more) available on every element via the generic HtmlElement<T> base class.
  • Type-safe enums for values such as input types, form method/enctype/target, text direction, and media track kind.
  • Targets .NET Standard 2.0, so it works from .NET Framework, .NET Core, and modern .NET.

Installation

dotnet add package FluentHtmlStringBuilder

Or via the Package Manager Console:

Install-Package FluentHtmlStringBuilder

Quick start

using FluentHtmlStringBuilder;
using FluentHtmlStringBuilder.Elements.Display;

var card = new Div()
	.HasClass("card")
	.HasId("welcome-card")
	.HasContent(new HtmlH2().HasContent(new HtmlTextNode("Welcome!")))
	.HasContent(new HtmlParagraph().HasContent(new HtmlTextNode("Hello, <world>!")));

string html = card.ToString();
// <div class="card" id="welcome-card"><h2>Welcome!</h2><p>Hello, &lt;world&gt;!</p></div>

Usage

Composing elements

Every element derives from HtmlElement and exposes its children through Content. Use HasContent(...) to append child elements fluently:

var list = new HtmlUnorderedList()
	.HasItem(new HtmlListItem().HasContent(new HtmlTextNode("First")))
	.HasItem(new HtmlListItem().HasContent(new HtmlTextNode("Second")));

Console.WriteLine(list);
// <ul><li>First</li><li>Second</li></ul>

Global & ARIA attributes

HtmlElement<T> exposes fluent methods for common global and accessibility attributes on every element:

var badge = new Span()
	.HasClass("badge")
	.HasTitle("Status")
	.HasAriaLabel("Active status")
	.HasData("state", "active");
// <span class="badge" title="Status" aria-label="Active status" data-state="active"></span>

Forms

using FluentHtmlStringBuilder.Elements.Forms;
using FluentHtmlStringBuilder.Elements.Forms.InputTypes;

var form = new HtmlForm()
	.HasAction("/login")
	.HasMethod(FormMethods.post)
	.HasContent(new HtmlInputLabel().For("email").HasContent(new HtmlTextNode("Email")))
	.HasContent(new HtmlInputEmail().HasId("email").HasName("email").IsRequired())
	.HasContent(new HtmlButton().HasContent(new HtmlTextNode("Sign in")));

string html = form.ToString();

Documents

using FluentHtmlStringBuilder.Elements.Display;

var document = new HtmlDocument()
	.HasContent(new HtmlDocumentHead()
		.HasContent(HtmlMeta.Utf8())
		.HasContent(HtmlMeta.Viewport())
		.HasContent(new HtmlLink().HasRel("stylesheet").HasHref("site.css")))
	.HasContent(new HtmlDocumentBody()
		.HasContent(new HtmlH1().HasContent(new HtmlTextNode("Hello!"))));

string html = "<!DOCTYPE html>" + document;

Escaped vs. raw text

  • HtmlTextNode escapes &, <, >, ", and ' so user-supplied content renders safely.
  • HtmlRawTextNode writes the given string verbatim — use it only for trusted content, such as inline CSS or JavaScript:
using FluentHtmlStringBuilder.Elements.RawText;

var style = new HtmlStyle().HasCss("body { margin: 0; }");
// <style>body { margin: 0; }</style>

Supported elements

Category Namespace Elements
Containers FluentHtmlStringBuilder Div, Span
Lists FluentHtmlStringBuilder HtmlUnorderedList, HtmlOrderedList, HtmlListItem
Text & display FluentHtmlStringBuilder.Elements.Display HtmlParagraph, HtmlH1HtmlH6, HtmlTextNode, HtmlAnchor, HtmlImage, HtmlMeta, HtmlLink, HtmlDefinitionList, HtmlDefinitionTerm, HtmlDefinitionDescription
Documents FluentHtmlStringBuilder.Elements.Display HtmlDocument, HtmlDocumentHead, HtmlDocumentBody
Forms FluentHtmlStringBuilder.Elements.Forms HtmlForm, HtmlButton, HtmlInputLabel, HtmlTextArea, HtmlTable, HtmlTableRow, HtmlTableCell, HtmlTableHeader, HtmlSelect, HtmlSelectOption, HtmlSelectOptGroup, HtmlFormFieldset, HtmlFormLegend
Form inputs FluentHtmlStringBuilder.Elements.Forms.InputTypes HtmlInputText, HtmlInputEmail, HtmlInputPassword, HtmlInputCheckbox, HtmlInputRadio, HtmlInputNumber, HtmlInputDate, HtmlInputDateTime, HtmlInputMonth, HtmlInputWeek, HtmlInputTime, HtmlInputColor, HtmlInputFile, HtmlInputHidden, HtmlInputImage, HtmlInputRange, HtmlInputSearch, HtmlInputTelephone, HtmlInputUrl, HtmlInputButton, HtmlInputSubmit, HtmlInputReset
Semantic layout FluentHtmlStringBuilder.Elements.Semantic HtmlHeader, HtmlNav, HtmlMain, HtmlFooter, HtmlSection, HtmlArticle, HtmlAside
Interactive FluentHtmlStringBuilder.Elements.Interactive HtmlDetails, HtmlSummary, HtmlDialog, HtmlTemplate
Media FluentHtmlStringBuilder.Elements.Media HtmlVideo, HtmlAudio, HtmlSource, HtmlTrack, HtmlCanvas, HtmlSvg, HtmlPicture, HtmlFigure, HtmlFigureCaption
Raw text FluentHtmlStringBuilder.Elements.RawText HtmlScript, HtmlStyle, HtmlRawTextNode
Attribute model FluentHtmlStringBuilder.Attributes HtmlAttribute, HtmlAttributeCollection, HtmlAttributeValueCollection

Target framework

  • .NET Standard 2.0
  • .NET Standard 2.1
  • .NET 8.0
  • .NET 10.0

License

Licensed under the MIT License — free to use, modify, and distribute, including in commercial and closed-source projects.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 105 7/9/2026