Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

shadowrootcustomelementregistry — deferred registry assignment

A boolean attribute on template that leaves a declarative shadow root without a custom element registry. It allows a registry to be assigned later through initialize(), rather than automatically using the document's registry.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<template shadowrootmode="open" shadowrootcustomelementregistry>…</template>

shadowrootcustomelementregistry is a boolean attribute on template, used with declarative shadow DOM. It does not create a shadow root by itself: a valid shadowrootmode, such as open, is also needed. Presence is what matters; giving it the value "false" does not disable it and is not valid HTML boolean-attribute syntax.

When the parser creates this root, the attribute's presence sets its registry to null and preserves that state until explicit initialization. Without the attribute, the parser uses the host's document registry. The attribute neither creates a new CustomElementRegistry, selects a registry by name, nor registers element definitions.

A script can create a registry with new CustomElementRegistry(), add a definition with define(), and call registry.initialize(root). That method assigns the registry to the root and descendant elements whose registries are null, then attempts to upgrade elements using the definitions. An already assigned registry cannot be replaced this way.

The corresponding HTMLTemplateElement.shadowRootCustomElementRegistry property reflects the attribute as a DOMString, not a boolean; the standard deliberately leaves room for extension. The example requires implementations of every mechanism it uses—declarative shadow DOM support alone is insufficient.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Deferred custom element registry</title>
<div id="host">
  <template shadowrootmode="open" shadowrootcustomelementregistry>
    <demo-item></demo-item>
  </template>
</div>
<pre id="result"></pre>
<script>
  const root = document.getElementById('host').shadowRoot;
  const item = root.querySelector('demo-item');
  class DemoItem extends HTMLElement {}
  const registry = new CustomElementRegistry();
  registry.define('demo-item', DemoItem);
  const before = item instanceof DemoItem;
  registry.initialize(root);
  const after = item instanceof DemoItem;
  document.getElementById('result').textContent =
    `before: ${before}\nafter: ${after}`;
</script>
</html>

Result

before: false
after: true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources