Skip to content

StyleScope

Bound a subtree to theme, finite variant, color mode, and density markers only.

Import from hedron import StyleScope
Distribution hedron
Backend activity No
Normal render mode RenderMode.FRAGMENT

Live demo

Scoped panel

Theme, color mode, and density markers only.

The preview is a local docs simulation (not a running Hedron server). Interactive demos show a “Simulated HTMX” trace when applicable.

Basic use

from hedron import StyleScope, Text

component = StyleScope(Text('Scoped panel'), theme='aurora', variant='dense', color_mode='dark', density='compact')

Compose under Page for full documents, or return from a fragment route for HTMX swaps.

How it works

StyleScope is a visible boundary for theme, finite variant, color mode, and density only. Presentation is marker-driven (data-hedron-*) and styled by first-party CSS; recipe defaults are rejected.

This component's core behavior is server-rendered HTML and does not require a browser runtime. The preview is ordinary semantic HTML, so keyboard, form, link, and disclosure behavior comes from the platform.

Constructor and parameters

StyleScope(*nodes, *, theme=None, color_mode=None, density=None, variant=None, id=None, class_=None, mark=None)
Parameter Type Meaning
nodes NodeLike StyleScope body content.
theme str | None Optional registered theme name emitted as data-hedron-theme.
variant str | None Optional finite registered variant emitted as data-hedron-variant. Unknown names fail closed.
color_mode light | dark | None Optional color-mode marker (data-hedron-color-mode).
density compact | comfortable | spacious | None Optional density marker (data-hedron-density).

Composition and backend behavior

Keep StyleScope at the smallest semantic boundary. Fragment routes should return only the replaced region and preserve stable target IDs across success, validation, empty, loading, and error responses.

StyleScope is primarily presentational; keep any mutation on an explicit action or component route.

Accessibility

Prefer StyleScope when a region must override theme, finite variant, color mode, or density without application CSS.

Security

Escaping and SafeUrl / TrustedHtml are framework concerns; authorization and data exposure remain application code. Redact secrets before rendering.

Common mistakes

  • Do not pass recipe defaults or arbitrary CSS; only theme, finite variant, color_mode, and density are supported.
  • Do not copy docs-preview JavaScript into an application server.

Testing

from hedron import RenderMode, render

result = render(component, mode=RenderMode.FRAGMENT)
assert result.html
assert not result.diagnostics

All component demos · Built-in API · Testing