Attributes

Manage HTML attributes through a structured rendering model.

Why attributes need structure

Attributes are one of the core responsibilities of PageBuilder. Instead of assembling attribute strings manually inside views or rendering code, PageBuilder provides a structured attribute system shared by all builders.

In a simple page, manually writing a few HTML attributes is not difficult. In a real component system, however, attributes quickly become dynamic. Conditions, state, composition, accessibility, and reuse all make ad hoc attribute generation harder to maintain.

PageBuilder solves this by giving builders a centralized way to register, store, and render attributes. This improves consistency, reduces fragile string concatenation, and makes builders easier to understand and maintain.

The attribute model

At the base level, builders manage attributes through a dictionary-like internal model. Attributes are accumulated as structured data first, then rendered into final HTML only when the builder writes its output. This makes it possible to:

Set attributes progressively
Override or remove attributes safely
Build attributes through fluent APIs
Keep rendering code readable

Common attribute categories

PageBuilder supports several common categories of attributes through dedicated methods or conventions.

Standard attributes

Standard attributes are handled through the generic attribute API. Builders can set, update, or remove them as part of their internal state before the final HTML is emitted. This keeps attributes aligned with builder state instead of scattering them across view logic. Typical examples include:

id , name , role , tabindex
Custom attributes specific to a component

Data attributes

data-* attributes are especially important in builder-based systems because they provide a safe way to attach behavior metadata or component state to rendered elements. PageBuilder supports them as structured attributes rather than forcing each builder to hardcode string fragments manually.

JavaScript initialization hooks
Component identifiers
Custom behavior flags
Debug markers

ARIA attributes

Accessibility-related attributes are part of the same structured system. Builders can register aria-* attributes just like other semantic attributes. This is important because accessible components often require stateful aria values that depend on rendering context. PageBuilder makes it easier to express these values as part of the component logic itself.

Boolean-like attributes

Some HTML attributes behave like flags rather than ordinary key-value pairs. A common example is disabled . PageBuilder treats these attributes deliberately so that builders can express them through structured state instead of relying on fragile conditional string output. This keeps the generated HTML more predictable and the builder code easier to read.

Reserved concerns: class and style

Architectural design choice

Although class and style are technically HTML attributes, PageBuilder treats them as reserved concerns with their own dedicated systems. Classes and styles are too important, too stateful, and too compositional to be treated like ordinary attributes.

Component classes are managed through the internal class system
Reusable class generation is managed through CSS composers
Inline styles are managed through the style system

Why the attribute system matters in the pipeline

The attribute system is not isolated from the rest of PageBuilder. Builders use it while rendering inside the broader page pipeline. A builder may generate visible attributes for its output while also participating in page-level registration through PageInformation . This is another reason why attributes need to be structured: builders must remain predictable even when rendering becomes layered or stateful.

Recommended usage

Use the attribute API for semantic element state
Use data-* attributes for client-side metadata and behavior hooks
Use aria-* attributes deliberately for accessibility
Do not treat class and style as ordinary attributes
Keep attribute logic inside builders instead of spreading it across views

Continue with Styles

Understand inline style handling and how it complements the attribute system.

Styles →