HTML exportparts Global Attribute
The exportparts attribute passes the shadow parts of a nested web component up to its parent component, optionally renamed, so they can be styled with ::part().
Description
The exportparts attribute is a global HTML attribute used in conjunction with Web Components and the Shadow DOM. It allows a custom element to expose selected internal shadow parts so they can be styled from outside the component using the ::part() pseudo-element.
By default, styles inside a Shadow DOM are encapsulated, meaning external stylesheets cannot target internal elements. The exportparts attribute provides a controlled way to expose specific parts of a component’s internal structure without breaking encapsulation entirely.
This makes it especially useful when building reusable, themeable components that still maintain a clean separation between internal implementation and external styling.
How exportparts Works
Parts declared with the part attribute can already be styled one level up: from the document for a component used in the page, with my-button::part(button). exportparts is needed when components are nested: it is placed on the inner component, inside the outer component's shadow tree, and forwards (and optionally renames) the inner parts so that they become parts of the outer component and can be styled from the document.
Example: Simple Exported Part
Inner component (shadow DOM of <my-button>)
<button part="button">Click me</button>
Outer component (shadow DOM of <my-toolbar>)
<my-button exportparts="button"></my-button>
External CSS
my-toolbar::part(button) {
background-color: #4caf50;
color: white;
border-radius: 6px;
}
In this case, the button part of the inner component becomes a part of <my-toolbar> and can be styled from the document.
Renaming Exported Parts
You can rename parts when exporting them. This is useful for maintaining consistent naming conventions or avoiding conflicts.
<my-button exportparts="button: primary-button"></my-button>
Now it can be styled like this:
my-toolbar::part(primary-button) {
padding: 10px 16px;
}
Exporting Multiple Parts
Multiple parts can be exported by separating them with commas:
<custom-card exportparts="header, body, footer"></custom-card>
Or with renaming:
<custom-card exportparts="header: card-header, footer: card-footer"></custom-card>
Why Use exportparts?
The exportparts attribute helps solve common styling challenges when working with Shadow DOM components:
- Allows safe and intentional styling from outside a component
- Preserves encapsulation while enabling customization
- Prevents direct DOM access or reliance on internal structure
- Encourages reusable and themeable UI components
This is particularly useful for design systems, UI libraries, and reusable widgets.
Relationship to part and ::part()
| Feature | Purpose |
|---|---|
part |
Defines a stylable element inside a Shadow DOM |
exportparts |
Exposes internal parts to the outside |
::part() |
Selects and styles exported parts |
Together, these features create a controlled styling API for web components.
Notes and Best Practices
- Only elements with a
partattribute can be exported. - Exported parts do not expose the full DOM - only styling access.
- Avoid over-exporting parts to keep components maintainable.
- Use consistent naming to make styling intuitive for consumers.
Syntax
<custom-element exportparts="internal-name: external-name"></custom-element>
Values
- internal-nameThe name defined via the part attribute inside the child component's shadow DOM.
- external-nameThe name that will be visible to the outside world (the document or the grandparent).
Example
Browser Support
The following information will show you the current browser support for the HTML exportparts global attribute. Hover over a browser icon to see the version that first introduced support for this HTML global attribute.
Desktop





Tablets & Mobile





