I have an HTML custom element that inherits from HTMLElement. The template contains:
<input type="text" part="input"/>
Sample CSS:
my-element::part(input) {
padding-right: 1px;
}
Sample JavaScript (inside class MyElement {}):
this.input.style.paddingRight = "25px";
The Style inspector in DevTools (Rules in Firefox) crosses out the ::part declaration for padding-right and shows:
element.style {
padding-right:25px;
}
But the computed value inspector shows padding-right:1px and it's rendered as 1px.
The JS code is running after the page fully loads. I don't see a straightforward way around this behavior. If I modify a CSS property for this element in JS, then I cannot declare it CSS. At least not with padding.
Why does a pseudo-element of the custom element take precedence over the element's own style?
The fact that the Style/Rules inspector disagrees with the Computed inspector makes me think this is a bug in both browsers, but I'm no expert. I have not yet tried this on browserstack to check other platforms. Right now I'm focused on working around this unexpected behavior.
It's a bit of work to create a working demo snippet, and the behavior is the same across Firefox and Chrome in Win11, so I'll wait until someone requests it.


::partis to allow to overwrite the style of the custom element; you add a basic style to your elements but expose elements withpartso that the user of the component can change the style. Due to that it has a higher specificity.If I modify a CSS property for this element in JS, then I cannot declare it CSS. At least not with padding.what do you mean with that?::parttakes precedence over modifying the value in JavaScript withinput.style. To me this was a surprise because it's the first time I've seen a CSS rule overrideelement.style. Not even CSS#iddoes that.importantsolves it, thankfully.