- Home
- /
- Foundation
- /
- DMBPageBuilder
- /
- CSS Composers
CSS Composers
Separate reusable CSS logic from structural rendering.
Overview
The CSS system of PageBuilder is based on a simple idea: not all CSS class logic belongs directly inside a builder. Some class logic is local to a component, while other class logic represents a reusable styling rule set that should remain independent from the component structure itself.
PageBuilder addresses this distinction through CSS composers.
Why CSS composers exist
If every CSS class were hardcoded directly into every builder, builders would quickly become difficult to evolve. Structural rendering logic and styling logic would be tightly coupled, and reusable style systems would be duplicated across components.
CSS composers exist to solve that problem. They let builders delegate reusable class generation to specialized objects while keeping the builder focused on HTML structure and component behavior.
What a CSS composer is
A CSS composer is a class whose responsibility is to generate CSS classes according to a reusable rule set. Instead of directly writing every class into the builder, the builder can attach one or more composers and let them contribute to the final class list during rendering.
This means the final class value of a builder is often the result of multiple layers:
The distinction between component classes and composer classes
PageBuilder deliberately separates local component classes from reusable CSS logic.
Two levels of CSS identity
Component classes define the immediate CSS identity of the builder — they are part of the builder's own structure and implementation. Composer classes represent reusable style rules that can be shared across builders or across a family of components. This distinction prevents the CSS system from collapsing into unstructured class concatenation.
When to use a CSS composer
A composer is appropriate when CSS class generation reflects a reusable styling concern rather than a one-off rendering adjustment. Typical cases include:
If the class change is temporary, local, and specific to one rendering path, an internal class adjustment is usually sufficient. If the class logic represents a reusable rule system, a composer is the better abstraction.
How composers participate in rendering
During rendering, the builder collects its internal component classes and then asks its attached CSS composers to contribute their own class lists. The final class attribute is then assembled from this combined output.
This means composers do not render HTML themselves. Their role is to participate in the final class value of the builder. They are part of the rendering model, but at the styling layer rather than at the structural HTML layer.
Why this improves extensibility
By keeping reusable CSS logic separate from the structure of the builder, PageBuilder becomes easier to extend. A component can evolve structurally without forcing all styling logic to be rewritten, and a styling rule can evolve without forcing the builder to absorb more internal complexity.
This is one of the reasons PageBuilder works well as a foundation for larger modules and UI libraries.
Relationship with HtmlBuilderBase
HtmlBuilderBase provides the infrastructure required to store and manage composers. A builder can register, retrieve, and clone composers as part of its rendering state. This is important because composers are not isolated helpers — they are first-class participants in the builder model. When a builder is cloned or composed, its composer state must remain coherent with the rest of the rendering state.
Design benefits
Recommended usage
This is the end of this track
Continue exploring the full PageBuilder architecture through Extensibility or HtmlBuilderBase.
HtmlBuilderBase → Extensibility →