CKTIS / CSS
:defined — the defined-element pseudo-class
The :defined pseudo-class selects elements considered defined by the document language. In HTML, it matches ordinary built-in elements and successfully constructed custom elements, allowing you to distinguish a component awaiting its definition from one that has been upgraded.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
:defined:defined is a pseudo-class with no arguments. Its meaning is determined by the document language; if that language makes no defined-versus-undefined distinction, all elements match. In HTML, an ordinary p element is defined. But a p created with a valid is value as a candidate for a customized built-in element can remain undefined until it is successfully upgraded.
A custom element awaiting its definition does not match :defined. After a successful upgrade, it matches. Registering a name alone does not guarantee success for every instance: failed construction does not produce a successfully defined element.
Use demo-card:defined for the defined component and demo-card:not(:defined) for the opposite state. Matching does not imply that data fetching, image loading, or asynchronous application initialization has finished.
The example records the state before and after customElements.define(). The final border is solid; the pre-registration state might never be painted. Avoid globally hiding :not(:defined): if the definition never arrives, content can remain unavailable.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:defined demo</title>
<style>
demo-card { display: block; padding: 8px; }
demo-card:not(:defined) { border: 2px dashed; }
demo-card:defined { border: 2px solid; }
</style>
<demo-card>Demo</demo-card>
<pre id="output"></pre>
<script>
const card = document.querySelector('demo-card');
const output = document.querySelector('#output');
const lines = [
`built-in: ${output.matches(':defined')}`,
`before: ${card.matches(':defined')}`
];
customElements.define('demo-card', class extends HTMLElement {});
lines.push(`after: ${card.matches(':defined')}`);
output.textContent = lines.join('\n');
</script>
</html>Result
built-in: true before: false after: true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.