---
title: IHtmlNode
summary: API reference for IHtmlNode.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-09-17
library: SAIF.Framework.Web.Mvc
reference_type: package
---

# IHtmlNode

Defines the contract for a composable, in-memory HTML element (children, inner HTML, attributes, CSS classes, tag name, render mode) that `HtmlElement` implements; a public building block not otherwise consumed inside this library.*

## Purpose
- Defines the contract for a composable, in-memory HTML element (children, inner HTML, attributes, CSS classes, tag name, render mode) that `HtmlElement` implements; a public building block not otherwise consumed inside this library.*

## Context
- Namespace: `SAIF.Web.Mvc.UI`
- Assembly/package: `SAIF.Framework.Web.Mvc (source-shipping NuGet package)`
- Kind: interface

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| Children | `IList<IHtmlNode> Children { get; }` | The nested child nodes composed under this node; implementations render these in place of raw inner HTML when present. |
| InnerHtml | `string InnerHtml { get; }` | Read-only. The node's rendered inner HTML — either the concatenation of its children or previously assigned raw HTML, depending on the implementation. |
| RenderMode | `TagRenderMode RenderMode { get; }` | Read-only. The tag rendering mode (e.g. normal, start/end tag only, or self-closing) that controls how `WriteTo` emits the element. |
| TagName | `string TagName { get; }` | Read-only. The HTML tag name the node renders as. |
| AddClass(string[]) | `IHtmlNode AddClass(params string[] classes)` | Adds one or more CSS class names to the node's `class` attribute and returns the node for chaining. |
| AppendTo(IHtmlNode) | `IHtmlNode AppendTo(IHtmlNode parent)` | Composes this node as a child of `parent` (adding it to `parent.Children`) and returns this node for chaining. |
| Attributes() | `IDictionary<string, string> Attributes()` | Returns the node's live attribute dictionary for direct reads or mutation. |
| Attribute(string) | `string Attribute(string key)` | Returns the current value of the named attribute. |
| Attribute(string, string) | `IHtmlNode Attribute(string key, string value)` | Sets the named attribute, replacing any existing value, and returns the node for chaining. |
| Attribute(string, string, bool) | `IHtmlNode Attribute(string key, string value, bool replaceExisting)` | Sets the named attribute, replacing or preserving an existing value depending on `replaceExisting`, and returns the node for chaining. |
| Attributes(object) | `IHtmlNode Attributes(object attributes)` | Merges the properties of an anonymous object into the attribute dictionary, replacing existing values, and returns the node for chaining. |
| Attributes&lt;TKey, TValue&gt;(IDictionary&lt;TKey, TValue&gt;) | `IHtmlNode Attributes<TKey, TValue>(IDictionary<TKey, TValue> attributes)` | Merges the supplied dictionary into the node's attributes, replacing existing values, and returns the node for chaining. |
| Attributes&lt;TKey, TValue&gt;(IDictionary&lt;TKey, TValue&gt;, bool) | `IHtmlNode Attributes<TKey, TValue>(IDictionary<TKey, TValue> attributes, bool replaceExisting)` | Merges the supplied dictionary into the node's attributes, replacing or preserving existing values per `replaceExisting`, and returns the node for chaining. |
| Css(string, string) | `IHtmlNode Css(string key, string value)` | Sets an inline `style` declaration on the node and returns the node for chaining. |
| Html(string) | `IHtmlNode Html(string value)` | Discards any composed children and sets the node's raw inner HTML to the given string, then returns the node for chaining. |
| PrependClass(string[]) | `IHtmlNode PrependClass(params string[] classes)` | Adds one or more CSS class names ahead of the node's existing classes and returns the node for chaining. |
| Template() | `Action<TextWriter> Template()` | Returns the callback previously assigned via `Template(Action<TextWriter>)`, or `null` if none was set. |
| Template(Action&lt;TextWriter&gt;) | `IHtmlNode Template(Action<TextWriter> value)` | Assigns a callback that, when present, takes over rendering of the node's inner content ahead of its children or inner HTML, and returns the node for chaining. |
| Text(string) | `IHtmlNode Text(string value)` | Sets the node's encoded inner text, discarding any composed children, and returns the node for chaining. |
| WriteTo(TextWriter) | `void WriteTo(TextWriter output)` | Writes the fully composed element — start tag, then template callback, children, or inner HTML (in that priority order), then end tag — to the given writer. |

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `src/Web.Mvc/UI/IHtmlNode.cs`
