Indeed, Elements created with Custom Elements but lacking shadowDOM function as regular DOM elements, such as a simple <div>
or <p>
.
It is only through the use of shadowRoots
that CSS can be scoped (or even id
attributes)
Enabling external styling through:
- CSS properties
- ::part
- theme
Distinct technologies within Web Components
- Templates
- Custom Elements
- shadowDOM
Each of these can stand alone without depending on the others
You are able to apply a shadowRoot to any regular DOM element:
document.querySelector("DIV").attachShadow({mode:"open"})
This action does not transform them into a Custom Element, but it does create a scoped area for CSS.
Incorporate shadowDOM only when necessary. (unfortunately, many libraries enforce shadowDOM usage)
Moreover, you have complete freedom to invent any tags you desire.
<pie-chart>
<slice size="90" stroke="green">HTML</slice>
<slice size="1" stroke="red">JavaScript</slice>
<slice size="9" stroke="blue">CSS</slice>
</pie-chart>
The tag <pie-chart>
represents a Web Component/Custom Element, whereas <slice>
remains unclassified (and cannot be classified).
For more information, visit my blogs on DEV.to: