Styles

Manage inline styles through a structured rendering system.

Overview

In PageBuilder, inline styles are treated as a first-class rendering concern. Instead of concatenating style strings manually, builders manage styles through a dedicated internal system that keeps style output explicit, structured, and predictable.

This is important because style generation often becomes dynamic in real components. Layout state, sizing rules, temporary overrides, and internal rendering decisions all make ad hoc style string assembly harder to maintain over time.

Why styles need a dedicated system

Deliberate design decision

Although the style attribute is technically just another HTML attribute, PageBuilder does not treat it like an ordinary key-value pair. Inline styles are often built progressively, modified conditionally, overridden temporarily, and composed from multiple rendering decisions — so they require their own structured model.

The style model

At the base level, PageBuilder stores inline styles as structured key-value entries. A builder can register style values incrementally, and the final style attribute is generated only when the builder renders itself. This approach makes it possible to:

Add styles progressively
Replace styles safely
Remove styles when they are no longer needed
Keep rendering code readable and explicit

How styles differ from classes

PageBuilder makes a clear distinction between classes and styles.

Classes express reusable styling identity and reusable styling rules
Inline styles express direct rendering decisions tied to the current output

In practice: use classes and CSS composers for reusable styling systems, and use inline styles when the rendering output requires a direct style value. This distinction helps prevent builders from mixing structural styling concerns with highly local rendering concerns.

Typical use cases

Inline styles are particularly useful when a component needs to express rendering values that are difficult or unnecessary to encode through reusable CSS classes. Typical examples include:

Dynamic width or height values
Runtime spacing adjustments
Inline positioning values
Temporary visual overrides required by component state

Why structured styles matter in complex builders

As builders become more compositional, styles are often influenced by internal rendering decisions. A builder may need to temporarily apply a style, render a fragment, then restore the previous style state. A structured style system makes this far safer than raw style string concatenation. It also keeps builder behavior more understandable when internal rendering paths become more advanced.

Relationship with HtmlBuilderBase

HtmlBuilderBase provides the internal style infrastructure used by all builders. It gives derived builders a consistent way to register style values and ensures that the final inline style attribute is emitted through the common rendering contract. This means style handling is not reinvented in every component — it is part of the shared rendering foundation.

Why styles matter in the full pipeline

Inline styles are generated at the builder level, but builders themselves render inside the broader PageBuilder pipeline. This means style output is part of a larger rendering system where consistency, composability, and predictability are important. Even though styles affect only the rendered HTML fragment, they still participate in the architectural discipline of the framework.

Recommended usage

Use inline styles for direct rendering values that belong to the component output
Use classes and CSS composers for reusable styling logic
Do not treat style as a generic attribute
Keep style registration close to the rendering logic that requires it
Prefer structured style management over concatenated inline style strings

Continue with CSS Composers

Understand reusable class generation and how it complements the inline style system.

CSS Composers →