CKTIS / CSS
::slotted() — styling slot-assigned elements
The ::slotted() pseudo-element lets a Shadow DOM stylesheet style slot-assigned elements that match its selector argument.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
::slotted(<compound-selector>)::slotted() represents elements assigned to a slot after assignment flattening. Use it in a stylesheet inside Shadow DOM; the prefix slot[name="label"] restricts selection to that slot.
The argument is one compound selector, such as .tag or span.tag, without combinators or a comma-separated list. Descendants of an assigned element are not automatically selected. Text nodes cannot match; their appearance can be affected through inheritance.
Specificity is one pseudo-element plus the argument: ::slotted(.tag) has (0,1,1). An appropriate pseudo-element may follow, such as ::slotted(.tag)::before. The example distinguishes two assigned elements by class.
Examples
<!doctype html>
<meta charset="utf-8">
<title>::slotted() demo</title>
<div id="host"><span slot="label" class="tag">A</span><span slot="label">B</span></div>
<pre id="result"></pre>
<script>
const host = document.getElementById('host');
const root = host.attachShadow({ mode: 'open' });
root.innerHTML = `
<style>
slot[name="label"]::slotted(.tag) {
background-color: rgb(255, 255, 0);
}
</style>
<slot name="label"></slot>
`;
requestAnimationFrame(() => {
document.getElementById('result').textContent =
Array.from(host.children, element =>
`${element.textContent}: ${getComputedStyle(element).backgroundColor}`
).join('\n');
});
</script>Result
A: rgb(255, 255, 0) B: rgba(0, 0, 0, 0)
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.