---
title: "Declarative Shadow DOM"
description: "Safari Technology Preview 162 enables declarative shadow DOM by default."
url: "https://swe.quest/articles/declarative-shadow-dom-9810e27126b5f6c2"
canonical: "https://webkit.org/blog/13851/declarative-shadow-dom/"
source: "WebKit"
published: "2023-02-13"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 3
tags: ["browsers","frontend"]
---

# Declarative Shadow DOM

A post on [WebKit](https://swe.quest/sources/webkit.md), published 2023-02-13, 3 min read, Announcement. Original: [https://webkit.org/blog/13851/declarative-shadow-dom/](https://webkit.org/blog/13851/declarative-shadow-dom/)

## Summary

Safari Technology Preview 162 enables declarative shadow DOM by default. A \`template\` element with a \`shadowrootmode\` attribute attaches its content as a shadow root on the parent element, so shadow trees work in server-side rendering and in no-JavaScript contexts such as email clients. Scripts can later reach the shadow root through \`ElementInternals\`. For backwards compatibility, \`attachShadow()\` on such an element returns the existing root emptied of its children instead of throwing. Parser APIs like \`innerHTML\` and \`DOMParser\` deliberately ignore the attribute to avoid new XSS vectors. A new \`cloneable\` option, set automatically for declarative roots, lets \`cloneNode()\` and \`importNode()\` copy shadow roots along with their hosts.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Browsers](https://swe.quest/tags/browsers.md) (Web & mobile)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)

## Prerequisites

- Web Components
- Shadow DOM basics
- Custom elements

## Keywords

Declarative Shadow DOM, Safari Technology Preview, WebKit, Web Components, ElementInternals, attachShadow

## Related posts

- [New WebKit Features in Safari 15.4](https://swe.quest/articles/new-webkit-features-in-safari-15-4-378317c134d40474.md): WebKit · 2022-03-14 · Medium · 13 min read · Browsers, CSS, Frontend, JavaScript
  Safari 15.4 ships over 70 WebKit additions, led by the \<dialog\> element with ::backdrop, lazy-loaded images, the :has() parent selector (shipped first in Safari), Cascade Layers, CSS containment, and new small/large/dynamic viewport units (svh, lvh, dvh and friends) that fix mobile viewport sizing.
- [WebKit Features in Safari 16.4](https://swe.quest/articles/webkit-features-in-safari-16-4-4fda9eefaadc5c33.md): WebKit · 2023-03-27 · Medium · 38 min read · Browsers, CSS, Frontend, Mobile
  Safari 16.4 ships 135 new web features and over 280 polish updates.
- [WebKit Features in Safari 16.5](https://swe.quest/articles/webkit-features-in-safari-16-5-78f214007552b969.md): WebKit · 2023-05-18 · Easy · 4 min read · Browsers, CSS, Frontend
  Safari 16.5 is mainly a polish and bug-fix release that adds CSS Nesting, the :user-valid and :user-invalid pseudo-classes, Apple Pay support for pre-orders and deferred payments, and disabling of the WebCodecs API in Lockdown Mode.
- [ElementInternals and Form-Associated Custom Elements](https://swe.quest/articles/elementinternals-and-form-associated-custom-elements-ed9dab4b8065833c.md): WebKit · 2023-02-06 · Medium · 4 min read · Browsers, Frontend, Accessibility, JavaScript
  Safari Technology Preview 162 enables ElementInternals and form-associated custom elements by default, letting custom elements set default ARIA roles and labels and take part in form submission and validation.
- [New WebKit Features in Safari 15.5](https://swe.quest/articles/new-webkit-features-in-safari-15-5-b4bbee299beae982.md): WebKit · 2022-05-16 · Easy · 5 min read · Browsers, CSS, Accessibility, Application security
  Safari 15.5 is mostly a polish and bug-fix release, adding three developer-facing technologies: the HTML \`inert\` attribute, which makes an element non-interactive and hides it from assistive technologies; the CSP Level 3 \`worker-src\` directive for restricting worker script sources; and WKWebView \`minimumViewportInset\`/\`maximumViewportInset\` APIs so apps can support the new CSS small, large and dynamic viewport units.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
