::part()
Quick Summary for ::part
The ::part CSS pseudo-element represents any element within a shadow tree that has a matching part attribute.
Code Usage for ::part
custom-element::part(foo) {   /* Styles to apply to the `foo` part */ } 
More Details for ::part

::part()

The ::part CSS pseudo-element represents any element within a shadow tree that has a matching part attribute.

custom-element::part(foo) {   /* Styles to apply to the `foo` part */ } 

Syntax

::part( <ident>+ )

Examples

HTML

<template id="tabbed-custom-element"> <style type="text/css"> *, ::before, ::after {   box-sizing: border-box;   padding: 1rem; } :host {   display: flex; } </style> <div part="tab active">Tab 1</div> <div part="tab">Tab 2</div> <div part="tab">Tab 3</div> </template>  <tabbed-custom-element></tabbed-custom-element> 

CSS

tabbed-custom-element::part(tab) {   color: #0c0dcc;   border-bottom: transparent solid 2px; }  tabbed-custom-element::part(tab):hover {   background-color: #0c0d19;   border-color: #0c0d33; }  tabbed-custom-element::part(tab):hover:active {   background-color: #0c0d33; }  tabbed-custom-element::part(tab):focus {   box-shadow:     0 0 0 1px #0a84ff inset,     0 0 0 1px #0a84ff,     0 0 0 4px rgba(10, 132, 255, 0.3); }  tabbed-custom-element::part(active) {   color: #0060df;   border-color: #0a84ff !important; } 

JavaScript

let template = document.querySelector("#tabbed-custom-element"); globalThis.customElements.define(template.id, class extends HTMLElement {   constructor() {     super();     this.attachShadow({ mode: "open" });     this.shadowRoot.appendChild(template.content);   } }); 

Result

Specifications

Specification
CSS Shadow Parts # part

See also

The part attribute - Used to define parts which can be selected by the ::part() selector The exportparts attribute - Used to transitively export shadow parts from a nested shadow tree into a containing light tree. Explainer: CSS Shadow ::part and ::theme

Last modified: Aug 12, 2021, by MDN contributors

Select your preferred language English (US)Français日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
"We're tight-fisted with property and money, yet think too little of wasting time, the one thing about which we should all be the toughest misers.”
Seneca
Random CSS Property

@viewport

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
user-zoom (@viewport) css reference