Shared elements allow you to synchronize state and data between different pages on the same site or across different domains. You define a source element on one page and reference it on consumer pages. The consumer can use entirely different markup, styles, or layouts while still participating in the shared state via specific capabilities.
Core Requirements for Consumers
To successfully consume a shared element, the consumer must provide:
data-source: A string in the format domain/path#elementId (e.g., thissite.com/blog/post#counter). The part after # is the shared ID.- Matching Capability: The consumer must include a capability tag (e.g.,
can-move, can-toggle, can-grow) that matches the capability declared on the source.
Permissions and Read-Only Modes
- Source Permissions:
shared or shared="read-write" (default): Allows both reading and writing state.shared="read-only" or shared="ro": The source only broadcasts updates; consumers cannot write back to it.
- Consumer Permissions:
- Add
data-source-read-only to a consumer to force local read-only behavior, even if the source is configured for read-write. PlayHTML will automatically apply a not-allowed cursor to these elements.
Combining Capabilities
Consumers can include additional capabilities that are local-only. Only the capabilities declared on the source are synchronized. For example, if a source has can-move, a consumer can have can-move (synchronized) and can-toggle (local-only).
<!-- Vanilla HTML Example -->
<!-- Source page (thissite.com) -->
<div id="couch" shared can-move style="font-size: 80px">🛋</div>
<!-- Consumer page (anothersite.com) -->
<div data-source="thissite.com#couch" can-move>🪑</div>