custom-element::part(foo) {
/* Styles to apply to the `foo` part */
}`::part()` CSS pseudo-element / notebook
`::part()` CSS pseudo-element
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
::part(<ident>+) {
/* ... */
}<template id="tabbed-custom-element">
<style>
*,
::before,
::after {
box-sizing: border-box;
padding: 1rem;
}
:host {
display: flex;
}
</style>
<div part="tab active">Tab A</div>
<div part="tab">Tab B</div>
<div part="tab">Tab C</div>
</template>
<tabbed-custom-element></tabbed-custom-element>tabbed-custom-element::part(tab) {
color: blue;
border-bottom: transparent solid 4px;
}
tabbed-custom-element::part(tab):hover {
background-color: black;
color: white;
}
tabbed-custom-element::part(tab active) {
border-color: blue !important;
}const template = document.querySelector("#tabbed-custom-element");
globalThis.customElements.define(
template.id,
class extends HTMLElement {
constructor() {
super().attachShadow({ mode: "open" }).append(template.content);
}
},
);