--- url: "https://web.dev/articles/shadowdom" titulek: "Shadow DOM 101 | Articles | web.dev" h1: "Shadow DOM 101 Stay organized with collections Save and categorize content based on your preferences." popis: "" jazyk: "en" kanonicka: "https://web.dev/articles/shadowdom" drobecky: ["Articles", "Shadow DOM 101"] zdroj: "live" wayback_snapshot: "" stazeno: "2026-09-14 00:03:11" znaku: 14228 slov: 2162 kodovani: "iso-8859-2" sha256: "b9d05ab7f297bc99053c155ae7ef2e8d0c07e32b543c3839f04b6f9b62a85b4e" --- Shadow DOM 101 Stay organized with collections Save and categorize content based on your preferences. Dominic Cooney Introduction Web Components is a set of cutting edge standards that: Make it possible to build widgets âŚwhich can be reused reliably âŚand which wonât break pages if the next version of the component changes internal implementation details. Does this mean you have to decide when to use HTML/JavaScript, and when to use Web Components? No! HTML and JavaScript can make interactive visual stuff. Widgets are interactive visual stuff. It makes sense to leverage your HTML and JavaScript skills when developing a widget. The Web Components standards are designed to help you do that. But there is a fundamental problem that makes widgets built out of HTML and JavaScript hard to use: The DOM tree inside a widget isnât encapsulated from the rest of the page. This lack of encapsulation means your document stylesheet might accidentally apply to parts inside the widget; your JavaScript might accidentally modify parts inside the widget; your IDs might overlap with IDs inside the widget; and so on. Web Components is comprised of three parts: [Templates](https://html.spec.whatwg.org/multipage/scripting.html#the-template-element) [Shadow DOM](https://www.w3.org/TR/shadow-dom/) [Custom Elements](https://html.spec.whatwg.org/multipage/custom-elements.html) **Shadow DOM** addresses the DOM tree encapsulation problem. The four parts of Web Components are designed to work together, but you can also pick and choose which parts of Web Components to use. This tutorial shows you how to use Shadow DOM. Hello, Shadow World With Shadow DOM, elements can get a new kind of node associated with them. This new kind of node is called a **shadow root**. An element that has a shadow root associated with it is called a **shadow host.** The content of a shadow host isnât rendered; the content of the shadow root is rendered instead. For example, if you had markup like this: ` ` then instead of ` ` your page looks like ` ` Not only that, if JavaScript on the page asks what the buttonâs `textContent` is, it isnât going to get âăăăŤăĄăŻă役ăŽä¸ç!â, but âHello, world!â because the DOM subtree under the shadow root is encapsulated. Separating Content from Presentation Now we'll look at using Shadow DOM to separate content from presentation. Let's say we have this name tag: `