ShadowRoot Class

https://dom.spec.whatwg.org/#interface-shadowroot

public sealed class ShadowRoot : DocumentFragment
Inheritance
DocumentFragment ShadowRoot

Properties

NameDescription
ActiveElementhttps://html.spec.whatwg.org/multipage/interaction.html#dom-documentorshadowroot-activeelement: the focused element, retargeted against the shadow root.
AdoptedStyleSheetsGets the list of the constructed style sheets adopted by the shadow root.
ClonableGets a value indicating whether the shadow root is copied when its host is cloned.
CustomElementRegistryhttps://dom.spec.whatwg.org/#dom-documentorshadowroot-customelementregistry
DelegatesFocusGets a value indicating whether the shadow root delegates focus to its first focusable element.
FullscreenElementGets the fullscreen element of the shadow tree (https://fullscreen.spec.whatwg.org/#dom-document-fullscreenelement): the fullscreen element of the document retargeted against the shadow root, when it is in the shadow tree.
HostGets the element to which the shadow root is attached.
InnerHtmlhttps://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml
ModeGets the encapsulation mode of the shadow root.
OnSlotChangeGets or sets the event handler of the slotchange event.
PointerLockElementGets the element the pointer is locked to when it is in the shadow tree (https://w3c.github.io/pointerlock/#dom-documentorshadowroot-pointerlockelement): the pointer-lock target retargeted against the shadow root.
SerializableGets a value indicating whether the shadow root is included when its host is serialized.
SlotAssignmentGets how slottables are assigned to the slots of the shadow root.
StyleSheetsGets the list of the style sheets of the shadow root.

ActiveElement

Focus.cs

https://html.spec.whatwg.org/multipage/interaction.html#dom-documentorshadowroot-activeelement: the focused element, retargeted against the shadow root.

public Element? ActiveElement { get; }

AdoptedStyleSheets

LinkStyle.cs

Gets the list of the constructed style sheets adopted by the shadow root.

public IList<CssStyleSheet> AdoptedStyleSheets { get; set; }

Gets a value indicating whether the shadow root is copied when its host is cloned.

public bool Clonable { get; }

CustomElementRegistry

ShadowRoot.cs

https://dom.spec.whatwg.org/#dom-documentorshadowroot-customelementregistry

public CustomElementRegistry? CustomElementRegistry { get; }

DelegatesFocus

ShadowRoot.cs

Gets a value indicating whether the shadow root delegates focus to its first focusable element.

public bool DelegatesFocus { get; }

FullscreenElement

Fullscreen.cs

Gets the fullscreen element of the shadow tree (https://fullscreen.spec.whatwg.org/#dom-document-fullscreenelement): the fullscreen element of the document retargeted against the shadow root, when it is in the shadow tree.

public Element? FullscreenElement { get; }

Gets the element to which the shadow root is attached.

public Element Host { get; }

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml

public string InnerHtml { get; set; }

Property value

string

Exceptions

TypeErrorException
Trusted Types are enforced and the default policy did not convert the value.

See also

Gets the encapsulation mode of the shadow root.

public ShadowRootMode Mode { get; }

OnSlotChange

DynamicMarkup.cs

Gets or sets the event handler of the slotchange event.

public Action<Event>? OnSlotChange { get; set; }

PointerLockElement

PointerLock.cs

Gets the element the pointer is locked to when it is in the shadow tree (https://w3c.github.io/pointerlock/#dom-documentorshadowroot-pointerlockelement): the pointer-lock target retargeted against the shadow root.

public Element? PointerLockElement { get; }

Serializable

ShadowRoot.cs

Gets a value indicating whether the shadow root is included when its host is serialized.

public bool Serializable { get; }

SlotAssignment

ShadowRoot.cs

Gets how slottables are assigned to the slots of the shadow root.

public SlotAssignmentMode SlotAssignment { get; }

StyleSheets

LinkStyle.cs

Gets the list of the style sheets of the shadow root.

public StyleSheetList StyleSheets { get; }

Methods

NameDescription
AppendHtml(string, SetHtmlOptions?)Parses the HTML and inserts the result after the last child.
AppendHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Parses the HTML and inserts the result after the last child, without the default sanitizer.
AppendHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Parses the HTML and inserts the result after the last child, without the default sanitizer.
ElementFromPoint(double, double)Returns the topmost element at a point of the viewport, retargeted against the shadow root: as Document.ElementFromPoint, but the elements of the shadow tree (and of the shadow trees that contain it) are not replaced by their shadow hosts, so the result can be an element of the shadow tree, or an element outside of it (e.g. the shadow host, or an element of the document). The member was defined by the obsolete Shadow DOM specification and is implemented by the browsers, but CSSOM View only defines it for the documents (https://github.com/w3c/csswg-drafts/issues/556).
ElementsFromPoint(double, double)Returns the elements at a point of the viewport, topmost first, retargeted against the shadow root: see ShadowRoot.ElementFromPoint and Document.ElementsFromPoint.
GetAnimations()Returns the relevant animations of the elements of the shadow tree, sorted by their composite order (https://drafts.csswg.org/web-animations-1/#dom-documentorshadowroot-getanimations).
GetHtml(GetHtmlOptions?)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-gethtml
GetSelection()Returns the selection of the node document. The member was defined by the obsolete Shadow DOM specification and is implemented by Blink and WebKit, but the Selection API does not define it.
PrependHtml(string, SetHtmlOptions?)Parses the HTML and inserts the result before the first child.
PrependHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Parses the HTML and inserts the result before the first child, without the default sanitizer.
PrependHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Parses the HTML and inserts the result before the first child, without the default sanitizer.
SetHtml(string, SetHtmlOptions?)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtml
SetHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtmlunsafe
SetHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtmlunsafe
SetInnerHtml(TrustedHtml)The innerHTML setter with a TrustedHtml value (https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml).
StreamAppendHtml(SetHtmlOptions?)Returns a writer that parses HTML and inserts the result after the last child as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).
StreamAppendHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Returns a writer that parses HTML and inserts the result after the last child as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).
StreamHtml(SetHtmlOptions?)Returns a writer that parses HTML and replaces the children with the result as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).
StreamHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Returns a writer that parses HTML and replaces the children with the result as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).
StreamPrependHtml(SetHtmlOptions?)Returns a writer that parses HTML and inserts the result before the first child as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).
StreamPrependHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)Returns a writer that parses HTML and inserts the result before the first child as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).

AppendHtml(string, SetHtmlOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result after the last child.

public void AppendHtml(string html, SetHtmlOptions? options = null)

AppendHtmlUnsafe overloads

AppendHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result after the last child, without the default sanitizer.

public void AppendHtmlUnsafe(TrustedHtml html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

AppendHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result after the last child, without the default sanitizer.

public void AppendHtmlUnsafe(string html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

ElementFromPoint(double, double)

CssomView.cs
  • Experimental (WEBPLATEXP0009)

Returns the topmost element at a point of the viewport, retargeted against the shadow root: as Document.ElementFromPoint, but the elements of the shadow tree (and of the shadow trees that contain it) are not replaced by their shadow hosts, so the result can be an element of the shadow tree, or an element outside of it (e.g. the shadow host, or an element of the document). The member was defined by the obsolete Shadow DOM specification and is implemented by the browsers, but CSSOM View only defines it for the documents (https://github.com/w3c/csswg-drafts/issues/556).

[Experimental("WEBPLATEXP0009", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public Element? ElementFromPoint(double x, double y)

ElementsFromPoint(double, double)

CssomView.cs
  • Experimental (WEBPLATEXP0009)

Returns the elements at a point of the viewport, topmost first, retargeted against the shadow root: see ShadowRoot.ElementFromPoint and Document.ElementsFromPoint.

[Experimental("WEBPLATEXP0009", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public IReadOnlyList<Element> ElementsFromPoint(double x, double y)

GetAnimations()

Document.Animations.cs

Returns the relevant animations of the elements of the shadow tree, sorted by their composite order (https://drafts.csswg.org/web-animations-1/#dom-documentorshadowroot-getanimations).

public IReadOnlyList<Animation> GetAnimations()

GetHtml(GetHtmlOptions?)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-gethtml

public string GetHtml(GetHtmlOptions? options = null)

GetSelection()

Selection.cs
  • Experimental (WEBPLATEXP0009)

Returns the selection of the node document. The member was defined by the obsolete Shadow DOM specification and is implemented by Blink and WebKit, but the Selection API does not define it.

[Experimental("WEBPLATEXP0009", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public Selection? GetSelection()

PrependHtml(string, SetHtmlOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result before the first child.

public void PrependHtml(string html, SetHtmlOptions? options = null)

PrependHtmlUnsafe overloads

PrependHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result before the first child, without the default sanitizer.

public void PrependHtmlUnsafe(TrustedHtml html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

PrependHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Insertion.cs

Parses the HTML and inserts the result before the first child, without the default sanitizer.

public void PrependHtmlUnsafe(string html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

SetHtml(string, SetHtmlOptions?)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtml

public void SetHtml(string html, SetHtmlOptions? options = null)

SetHtmlUnsafe overloads

SetHtmlUnsafe(TrustedHtml, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtmlunsafe

public void SetHtmlUnsafe(TrustedHtml html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

SetHtmlUnsafe(string, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.cs

https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-sethtmlunsafe

public void SetHtmlUnsafe(string html, SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)
Parameters
html string
options SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?
Exceptions
TypeErrorException
Trusted Types are enforced and the options or the value are not trusted.
See also

SetInnerHtml(TrustedHtml)

DynamicMarkup.cs

The innerHTML setter with a TrustedHtml value (https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-shadowroot-innerhtml).

public void SetInnerHtml(TrustedHtml html)

StreamAppendHtml(SetHtmlOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and inserts the result after the last child as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamAppendHtml(SetHtmlOptions? options = null)

Parameters

options SetHtmlOptions?

Returns

HtmlStreamWriter

StreamAppendHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and inserts the result after the last child as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamAppendHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

Parameters

options SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?

Returns

HtmlStreamWriter

Exceptions

TypeErrorException
Trusted Types are enforced, the options are not TrustedHtmlParserOptions and the default policy did not create them.

StreamHtml(SetHtmlOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and replaces the children with the result as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamHtml(SetHtmlOptions? options = null)

Parameters

options SetHtmlOptions?

Returns

HtmlStreamWriter

StreamHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and replaces the children with the result as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

Parameters

options SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?

Returns

HtmlStreamWriter

Exceptions

TypeErrorException
Trusted Types are enforced, the options are not TrustedHtmlParserOptions and the default policy did not create them.

StreamPrependHtml(SetHtmlOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and inserts the result before the first child as it is parsed (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamPrependHtml(SetHtmlOptions? options = null)

Parameters

options SetHtmlOptions?

Returns

HtmlStreamWriter

StreamPrependHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?)

DynamicMarkup.Streaming.cs
  • Experimental (WEBPLATEXP0002)

Returns a writer that parses HTML and inserts the result before the first child as it is parsed, without the default sanitizer (proposed by https://github.com/whatwg/html/pull/12758).

[Experimental("WEBPLATEXP0002", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public HtmlStreamWriter StreamPrependHtmlUnsafe(SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions? options = null)

Parameters

options SetHtmlUnsafeOptionsOrTrustedHtmlParserOptions?

Returns

HtmlStreamWriter

Exceptions

TypeErrorException
Trusted Types are enforced, the options are not TrustedHtmlParserOptions and the default policy did not create them.