HTML reference

part

The part attribute names selected elements inside a Shadow DOM so outside CSS can style them through the ::part() pseudo-element.

What you will learn

  • What Shadow DOM encapsulation means
  • How part and ::part() work together
  • How to expose only the styling hooks a component needs

Conceptual example

<!-- inside a component's shadow root -->
<button part="action">Save</button>

/* outside the component */
my-card::part(action) {
  border-radius: 0.5rem;
}

Shadow DOM normally keeps internal selectors private. A named part creates an intentional public styling API without exposing every internal element.

Design the API carefully

Related pages