VIEW THIS AS

Auto mode follows the Route Engine until you choose a viewpoint.

YOU ARE HERE

ROUTE CHECK

CONNECTED TO

WHAT NEXT

Use the canonical route for this room, or HELP if you are unsure.

The Gold Standard of Websites | Separating getHTML() Shadow-Root Serialization from innerHTML

Three learners review open books together at a classroom table, with stacks of textbooks, stationery and a whiteboard in the bright room.

A host contains light-DOM text, an open serializable shadow root and a nested non-serializable root. innerHTML returns only the light-DOM markup. getHTML() without options also omits roots; with serializableShadowRoots it includes the marked root; with an explicit list it can include the selected nested root. The lesson records each option before comparing strings.

This lesson continues The Gold Standard of Websites, the Gold Standard of Education and the How X Works hub. Every host, shadow tree, template string and comparison table is an original synthetic fixture. The lesson does not expose inaccessible roots, promise round-trip application state, sanitize untrusted markup, preserve event listeners or claim support where an implementation lacks the methods.

Record receiver, method, serializableShadowRoots option, explicit shadowRoots list, root mode, serializable flag, delegatesFocus, slot assignment, returned string, exception, browser build and unavailable behavior. Keep runtime objects, listeners and user data outside the serialized claim.

The WHATWG HTML serialization-method section, the HTML fragment serialization algorithm and the serializable shadow-root definition supply the living-standard rules. This lesson treats serialization as a bounded representation, not sanitization, cloning, persistence or a security approval.

THE GOLD STANDARD · WEBSITES

Both methods serialize descendants, but only getHTML() has options for selected shadow roots

innerHTML serializes the ordinary children of its context and omits shadow roots. Element.getHTML() and ShadowRoot.getHTML() use the HTML fragment serialization algorithm with options: serializableShadowRoots can include roots marked serializable, while an explicit shadowRoots list can include named roots regardless of that flag. Neither result is a live tree or a complete record of application state.

Fast route
Start with the decisive rule.
Start this route

Measurement route
Build the browser state and evidence ledger.
Start this route

Comparison route
Separate the nearest lookalikes.
Start this route

Transfer route
Change the context and retest.
Start this route

Reporting route
State limits and continue reading.
Start this route

Chapter contents

Open the full chapter index

1. Give the serialization rule

innerHTML and getHTML() can return similar strings for ordinary light DOM. The decisive difference appears when shadow-root options and eligible roots are involved.

Original worked example. A host with one paragraph and no shadow root yields equivalent ordinary markup from both methods. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Attach a serializable shadow root without changing the light DOM. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Record method, receiver, options and exact returned string. If this check fails, mark the claim unavailable and repair the method before continuing.

Keep method, object state and the final claim in separate fields so a matching visual result cannot rewrite platform evidence.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Contents · Next chapter

2. Start with no options

getHTML() does not automatically dump every shadow root. Without serializableShadowRoots or an explicit list, shadow roots are omitted.

Original worked example. host.getHTML() returns the light children while the shadow tree remains live but absent from the string. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Set serializableShadowRoots=true and repeat. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Treat omitted-by-option separately from absent-in-tree. If this check fails, mark the claim unavailable and repair the method before continuing.

Use a positive case, a clean negative case and an unavailable case. Unavailable evidence means the required field could not be established.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

3. Use the serializable flag correctly

The broad option includes roots whose serializable state is true. Open mode alone is not the inclusion rule.

Original worked example. An open root with serializable=false is omitted while a closed serializable root is eligible under the defined option. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Flip only the serializable flag. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Log mode and serializable as separate fields. If this check fails, mark the claim unavailable and repair the method before continuing.

Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

4. Understand the explicit list

The shadowRoots sequence can request specified roots regardless of their serializable flag, subject to the method’s rules and references actually available to the caller.

Original worked example. A script retains a reference to a non-serializable open root and supplies it explicitly. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Remove the reference and attempt to reconstruct it from markup alone. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Store object identity and list membership, not a guessed selector. If this check fails, mark the claim unavailable and repair the method before continuing.

Carry one plausible alternative through the state or geometry ledger, then choose the next observation that separates it from the leading account.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

5. Treat closed roots as capability-bounded

A closed root is not discoverable through host.shadowRoot. Serialization options do not grant a missing reference or bypass the platform’s access boundary.

Original worked example. Code that created a closed root retains its reference and can test explicit inclusion; unrelated code cannot obtain it from the host. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Run the same call from code with only the host reference. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Record how each root reference was obtained. If this check fails, mark the claim unavailable and repair the method before continuing.

Name the document, node, root, pseudo-element, target, offset or event involved. Similar visible results can come from different platform paths.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

6. Read declarative shadow markup

Included roots serialize through template markup carrying shadow-root attributes such as mode and relevant flags. That representation is not the same as an ordinary template already in light DOM.

Original worked example. The returned string contains a template shadowrootmode marker before shadow content. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Place an ordinary template element beside the host and compare. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Inspect attributes and context before calling both strings equivalent. If this check fails, mark the claim unavailable and repair the method before continuing.

Archive source, fixture, options, events, dimensions, browser version and raw exceptions so another reader can reproduce the conclusion.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

7. Separate receiver context

Element.getHTML() serializes the element’s children, while ShadowRoot.getHTML() serializes the root using its host as the context element. Receiver choice affects what is represented.

Original worked example. The host call includes light children plus selected roots; the root call begins from the shadow tree. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Move the nested root under a different host. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Log receiver type, host and serialization context. If this check fails, mark the claim unavailable and repair the method before continuing.

Keep method, object state and the final claim in separate fields so a matching visual result cannot rewrite platform evidence.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

8. Do not confuse serialization with sanitization

getHTML() reports markup according to serialization rules. It does not make dangerous markup safe for later insertion.

Original worked example. A string containing an event-handler attribute remains a security concern if used in an unsafe sink. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Pass a separately reviewed fixture through setHTML() and compare the different purpose. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Label serialize, sanitize, parse and insert as separate operations. If this check fails, mark the claim unavailable and repair the method before continuing.

Use a positive case, a clean negative case and an unavailable case. Unavailable evidence means the required field could not be established.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

9. Do not infer listeners or closures

HTML strings represent markup, not registered event listeners, JavaScript closures, timers or arbitrary object state.

Original worked example. A button appears in the string, but its addEventListener callback does not. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Recreate the markup in a detached document and test behavior. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. List every required state channel outside markup. If this check fails, mark the claim unavailable and repair the method before continuing.

Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

10. Keep form and user state bounded

Some current control state can differ from serialized attributes and default values. A markup string may therefore fail to reproduce what a user sees or has typed.

Original worked example. An input’s value property changes while its value attribute remains original; the string follows the serializable markup. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Update the attribute as well and compare. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Record property, attribute and returned string independently. If this check fails, mark the claim unavailable and repair the method before continuing.

Carry one plausible alternative through the state or geometry ledger, then choose the next observation that separates it from the leading account.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

11. Handle slots and distributed content

Slotted nodes remain light-DOM children; distribution is a rendering relationship. Serializing the host and roots does not flatten the composed tree into one visual sequence.

Original worked example. A light-DOM label appears in host markup while the shadow slot defines its rendered position. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Change the slot name without changing the text node. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Store light tree, shadow tree and assigned-slot evidence separately. If this check fails, mark the claim unavailable and repair the method before continuing.

Name the document, node, root, pseudo-element, target, offset or event involved. Similar visible results can come from different platform paths.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

12. Trace nested roots explicitly

A serializable outer root can contain a host for another root. Inclusion of the nested root still follows its own flag or explicit-list rule.

Original worked example. Outer root A is serializable, nested root B is not; the broad option includes A but omits B. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Add B to the explicit list. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Record each root’s host, depth, mode, flag and inclusion reason. If this check fails, mark the claim unavailable and repair the method before continuing.

Archive source, fixture, options, events, dimensions, browser version and raw exceptions so another reader can reproduce the conclusion.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

13. Compare strings without losing meaning

Whitespace, attribute ordering rules and escaping can make string comparison noisy. Compare parsed structural expectations as well as exact text when testing conformance.

Original worked example. Two expected fixtures differ only in escaped ampersands and template attributes. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Change a real node or shadow option while keeping formatting stable. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Preserve exact strings and a normalized structural map. If this check fails, mark the claim unavailable and repair the method before continuing.

Keep method, object state and the final claim in separate fields so a matching visual result cannot rewrite platform evidence.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

14. Test round trips cautiously

A string can be parsed later, including declarative shadow markup where supported, but round-trip equality does not guarantee runtime equivalence.

Original worked example. The reconstructed host contains the expected nodes but lacks listeners and live object references. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Add a stateful custom element and compare upgrade timing. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Define which structural properties the round trip must preserve. If this check fails, mark the claim unavailable and repair the method before continuing.

Use a positive case, a clean negative case and an unavailable case. Unavailable evidence means the required field could not be established.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

15. Repair common shortcuts

Open is not serializable, included markup is not sanitized, a returned string is not a clone, and equivalent light DOM does not establish shadow equivalence.

Original worked example. A blinded table asks readers to identify four unsupported conclusions. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Hide the strings and reason from receiver, flags and options. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Require the option ledger before interpreting output. If this check fails, mark the claim unavailable and repair the method before continuing.

Change one consequential premise while keeping the rest fixed. Predict the new branch before inspecting it and preserve disagreement.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

16. Answer practical questions

Use getHTML() when a controlled tool needs a shadow-aware representation and has the appropriate references. Use innerHTML for its narrower contract, and use separate safe insertion rules.

Original worked example. A component inspector exports author-approved serializable roots for debugging. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Change the job to accepting untrusted user markup. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Choose an API from the job and security boundary. If this check fails, mark the claim unavailable and repair the method before continuing.

Carry one plausible alternative through the state or geometry ledger, then choose the next observation that separates it from the leading account.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

17. Create a reproducible serialization ledger

A complete fixture saves the light tree, root graph, modes, flags, options and exact outputs for each method.

Original worked example. The table contains no-option, broad-option and explicit-list rows. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. Repeat with closed, nested and non-serializable roots. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Version markup, source anchors, browser and unavailable fields. If this check fails, mark the claim unavailable and repair the method before continuing.

Name the document, node, root, pseudo-element, target, offset or event involved. Similar visible results can come from different platform paths.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents · Next chapter

18. Use the living standard and continue

WHATWG HTML defines the current serialization options and fragment algorithm. Implementation support and declarative-shadow behavior must be dated.

Original worked example. The final route connects parsing and cloning lessons without collapsing them into serialization. The objects, values and observations are explicit so the reader can reconstruct the decision instead of trusting a label.

Changed-context transfer. When options evolve, rerun flags, explicit lists, nesting and round trips. State what changed, predict the consequence and revise only the conclusion that depended on that condition.

Practical evidence check. Save exact specification anchors and access date. If this check fails, mark the claim unavailable and repair the method before continuing.

Archive source, fixture, options, events, dimensions, browser version and raw exceptions so another reader can reproduce the conclusion.

Before closing, reconcile the original fixture against the chapter rule: identify the relevant objects, state, event order or geometry and the first missing obligation; change one condition and mark the first unsupported inference. Preserve the raw trace beside the revised result. End the chapter with three sentences: what the evidence establishes, what it does not establish and what observation would change the conclusion. This keeps the lesson useful when the browser, document or platform state changes. A strong record also names the datum, denominator, section or coordinate system that governed the decision, so a later reader can repeat the reasoning without importing an unstated shortcut.

Previous chapter · Contents

Sources and further study

WHATWG HTML, serialization methods. Used for the standard definitions, material mechanisms or method limits developed in this lesson.

WHATWG HTML, serializing HTML fragments. Used for the standard definitions, material mechanisms or method limits developed in this lesson.

WHATWG HTML, serializable shadow roots. Used for the standard definitions, material mechanisms or method limits developed in this lesson.

The worked examples and transfer checks are developed here and state their own assumptions. The linked sources support the underlying web-platform mechanisms, state and method limits.

Return to contents · Return to The Gold Standard of Websites