The CSS cascade resolves competing style declarations by origin, importance, specificity, and source order. For web components, a practical question comes first: which elements can a rule reach? A custom element participates in the cascade like any other element, so its tag name can be used as a selector for the host. section 7.7
Without a shadow root, a component uses the page DOM. Page rules can style elements created inside it, and styles declared inside it can affect the rest of the page. Those rules are not confined to the component merely because its markup came from a custom element. section 7.8.2
Listing 7.3 A web component using the page DOM
<style>
button { #1
background-color: black; #1
color: white; #1
} #1
</style>
<script>
class MyComponent extends HTMLElement {
connectedCallback() {
this.innerHTML = `
<style>
h1 { #2
border: 1px solid gray; #2
} #2
</style>
<button>Click me</button> #3
`;
}
}
customElements.define('my-component', MyComponent);
</script>
<h1>CSS with components</h1> #4
<my-component></my-component> #4
The page’s button rule styles the component’s button, while the component’s h1 rule styles the page heading. Neither rule is isolated because the component uses the page DOM. section 7.8.2
Host styling is a separate, useful choice: for example, a rule can change a custom element’s default inline display. The :not(:defined) selector can also hide or label a custom element while its definition has not yet been registered. section 7.7





