The core FluentHtml package provides the fundamental building blocks for HTML generation.
dotnet add package FluentHtml.Core
Abstract base class for all nodes in the component tree.
Children - List of child nodesAddChild(Node) - Add a child nodeAddChildren(IEnumerable<Node>) - Add multiple child nodesAddText(string) - Add a text content childAbstract base class for all HTML elements.
Fluent Methods:
Id(string) - Set the id attributeClass(string) - Add CSS classesStyle(string) - Set inline stylesTitle(string) - Set the title attributeData(string, string) - Set data attributesAria(string, string) - Set ARIA attributesRole(string) - Set the role attributeTabIndex(int) - Set tab orderHidden() - Mark as hiddenDisabled() - Mark as disabledRequired() - Mark as requiredReadOnly() - Mark as read-onlyChecked() - Mark as checkedCustom(string, string) - Set custom attributesOn(string, string) - Set event handlersAbstract base class for reusable UI components.
public abstract class Component : Node
{
public abstract Node Render();
}
public abstract class Component<T> : Component
{
protected T Data { get; }
protected abstract Node Build(T data);
}
FluentHtml.Core ships a framework-agnostic breadcrumb that renders semantic
nav > ol > li with no CSS framework dependency. For Bootstrap-styled breadcrumbs, use the
breadcrumb in FluentHtml.Bootstrap.
Breadcrumb(
BreadcrumbItem("Home"),
BreadcrumbItem("Data").AriaCurrent("page")
);
| Method | Description |
|---|---|
BreadcrumbItemComponent.AriaCurrent(value) |
Marks the current page for assistive technology. Framework-agnostic, unlike Active(), which adds Bootstrap’s active class name. |
BreadcrumbItemComponent.Separator(separator) |
Renders an aria-hidden separator inside the item. Accepts text or a Node. Nested because an ol may only contain li. |
BreadcrumbListComponent / BreadcrumbList(items) |
Supplies your own list element instead of relying on the factory’s implicit ol wrapper. |
// Control the list element and add separators
Breadcrumb(
BreadcrumbList(
BreadcrumbItem("Home").Separator("/"),
BreadcrumbItem("Data").AriaCurrent("page")
)
);
Collapsible trailing items and HTMX navigation are Bootstrap-only, since they require JavaScript and a CSS runtime.
All HTML elements have factory extension methods:
Div() // Creates <div></div>
Span("text") // Creates <span>text</span>
Button("Click") // Creates <button>Click</button>
Input() // Creates <input />
Form(children) // Creates <form>...</form>
Convert a node tree to HTML using the Renderer (using FluentHtml.Rendering;):
var renderer = new Renderer();
string html = renderer.Render(node);
// or write to a TextWriter:
renderer.Render(node, textWriter);
Low-level HTML output builder.
| Method | Description |
|---|---|
WriteRaw(string) |
Write raw HTML |
WriteOpenTag(string) |
Write opening tag |
WriteCloseTag(string) |
Write closing tag |
WriteSelfClosingTag(string) |
Write self-closing tag |
WriteAttribute(string, string) |
Write attribute with value |
WriteBooleanAttribute(string) |
Write boolean attribute |
WriteText(string) |
Write encoded text |
ToStringAndClear() |
Get output and clear buffer |
HTML encoding utilities.
| Method | Description |
|---|---|
Encode(string) |
Encode string for safe HTML output |
Encode(string, StringBuilder) |
Encode and append to builder |