- Home
- /
- Foundation
- /
- DMBPageBuilder
- /
- HtmlBuilderBase
HtmlBuilderBase
The technical foundation shared by all builders.
Overview
HtmlBuilderBase<TBuilder> is the core abstraction behind the PageBuilder builder system. It defines the shared mechanisms used by builders to manage attributes, styles, classes, internal state, cloning, and rendering.
Most important type to understand
If you want to understand how PageBuilder works internally, or if you want to build your own custom builders, HtmlBuilderBase is one of the most important types to understand.
Why a common base exists
Without a shared base class, every builder would need to reinvent the same rendering infrastructure:
This would quickly make the framework inconsistent and fragile. HtmlBuilderBase solves that by centralizing these responsibilities.
Main responsibilities
The base class is responsible for the low-level infrastructure required by builders. It typically handles:
Derived builders then add their own rendering semantics on top of that shared foundation.
Attributes
HtmlBuilderBase provides the common APIs used to manage HTML attributes. This includes generic attributes and convenience APIs for common patterns such as data-* and aria-* .
The attribute system is structured. Builders do not need to assemble raw attribute strings by hand. This improves correctness and keeps rendering logic readable. It is also important to note that class and style are treated as reserved concerns — they are not meant to be manipulated as ordinary attributes because they have dedicated systems of their own.
Styles
The base class provides a structured way to manage inline styles through a style dictionary. This allows a builder to incrementally register styles before they are finally rendered into the element.
This is particularly useful when rendering is stateful or when internal builder composition temporarily modifies style output. Inline styles remain explicit, but they are no longer fragile string concatenations scattered across rendering code.
Component classes
HtmlBuilderBase also manages component-level CSS classes. These classes form the direct CSS identity of the builder before additional styling rules are contributed by CSS composers. The base system distinguishes between internal component classes and reusable class logic generated by composers.
This distinction is important because not all CSS class logic belongs at the same level. Some class changes are local and temporary. Others represent reusable style systems.
CSS composers
The base class supports CSS composers through a dedicated composer collection. A composer is responsible for generating classes according to a reusable styling rule set. This allows builders to keep structural rendering logic separate from reusable CSS generation logic, and makes the framework easier to extend.
Internal state
HtmlBuilderBase provides an internal key-value store used by builders to keep structured state without exposing every implementation detail as a field or public property. This internal state system is especially useful for:
This is one of the reasons builders can remain fluent and compact while still supporting more advanced behavior.
Rendering contract
The base class defines the rendering contract through WriteTo(...) and WriteToCore(...) . WriteTo(...) is responsible for the shared rendering flow. It ensures that common processing such as debug metadata is applied consistently before delegating the actual HTML generation to WriteToCore(...) . Derived builders do not replace the full rendering model — they implement their specific rendering behavior inside the contract defined by the base class.
Cloning
Builders in PageBuilder are expected to support cloning when their design requires reuse or composition. HtmlBuilderBase provides the shared cloning pattern and lets derived builders extend it through their own internal clone logic.
This matters because builder composition often involves copying internal state, classes, composers, styles, and additional component-specific configuration. A correct cloning model helps keep builders predictable and avoids shared mutable state bugs.
How derived builders use it
A derived builder usually does three things on top of HtmlBuilderBase :
Everything else — attributes, styles, classes, rendering flow, composers, and internal state — comes from the base class. This is why HtmlBuilderBase is so central to the architecture of PageBuilder.
Why HtmlBuilderBase matters in the full pipeline
Builders do not live outside the PageBuilder pipeline. While rendering, they may not only emit HTML, but also contribute to the shared PageInformation used by the final document pipeline. This means the base builder model is part of a larger system:
This is one of the reasons the builder base class must remain disciplined and predictable.
Recommended usage
Continue with Attributes
Understand the attribute model in more detail and how it is managed by builders.
Attributes →