files/en-us/web/api/web_components/index.md
{{DefaultAPISidebar("Web Components")}}
Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated away from the rest of your code — and utilize them in your web apps.
As developers, we all know that reusing code as much as possible is a good idea. This has traditionally not been so easy for custom markup structures — think of the complex HTML (and associated style and script) you've sometimes had to write to render custom UI controls, and how using them multiple times can turn your page into a mess if you are not careful.
Web Components aims to solve such problems — it consists of three main technologies, which can be used together to create versatile custom elements with encapsulated functionality that can be reused wherever you like without fear of code collisions.
The basic approach for implementing a web component generally looks something like this:
{{domxref("CustomElementRegistry")}}
{{domxref("Window.customElements")}}
CustomElementRegistry object.{{domxref("Document.customElementRegistry")}}
{{domxref("Element.customElementRegistry")}}
connectedCallback()
disconnectedCallback()
adoptedCallback()
attributeChangedCallback()
Extensions for creating customized built-in elements
is global HTML attribute
CSS pseudo-classes
CustomElementRegistry.define().CSS pseudo-elements
part attribute.{{domxref("ShadowRoot")}}
{{domxref("ShadowRoot.customElementRegistry")}}
customElementRegistry option of {{domxref("Element.attachShadow()")}}, or later using {{domxref("CustomElementRegistry.initialize()")}}.{{domxref("Element")}} extensions
Element interface related to shadow DOM:
null if there is no shadow root attached.Relevant {{domxref("Node")}} additions
Node interface relevant to shadow DOM:
{{domxref("Event")}} extensions
Event interface related to shadow DOM:
true if the event will propagate across the shadow DOM boundary into the standard DOM, otherwise false.{{htmlelement("template")}}
{{htmlelement("slot")}}
The slot global HTML attribute
{{domxref("Element.assignedSlot")}}
{{domxref("Text.assignedSlot")}}
{{domxref("Element")}} extensions
Element interface related to slots:
CSS pseudo-elements
The {{domxref("HTMLSlotElement/slotchange_event", "slotchange")}} event
We are building up a number of examples in our web-components-examples GitHub repo. More will be added as time goes on.
{{Specifications}}
{{Compat}}