Widely availableSupported across all major browsers. Safe to use in production.

Overview

The part and exportparts HTML attributes expose elements of a shadow DOM as named parts, which can be selected by the ::part() CSS pseudo-element for styling.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
73
79
72
13.1
73
13.4
DOM API

The read-only part property of the Element interface contains a DOMTokenList object representing the part identifier(s) of the element. It reflects the element's part content attribute. These can be used to style parts of a shadow DOM, via the ::part pseudo-element.

73
79
72
13.1
73
13.4
Other

`::part`

73
79
72
13.1
73
13.4

The part global attribute contains a space-separated list of the part names of the element. Part names allows CSS to select and style specific elements in a shadow tree via the ::part pseudo-element.

73
79
72
13.1
73
13.4
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

HTML
/* Inside the Web Component */
/* <span part="label">Label</span> */

/* External CSS */
my-component::part(label) {
  color: #1e40af;
  font-weight: bold;
}

my-component::part(icon) {
  fill: currentColor;
  width: 20px;
}

Live demo

Partattribute. mechanism

::part() for Shadow DOM Partattribute. mechanism demo.

PreviewFullscreen

stylingexample

::part() for Shadow DOM stylingexample demo.

PreviewFullscreen

kapselization. boundary

::part() for Shadow DOM kapselization. boundary demo.

PreviewFullscreen

Use cases

  • Using Shadow parts

    The part and exportparts HTML attributes expose elements of a shadow DOM as named parts, which can be selected by the ::part() CSS pseudo-element for styling.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.

Powered by web-features