CSS :defined Pseudo-class

Definition and Usage

CSS :defined Pseudo-class is used to match any defined element.

This pseudo-class can be used for standard elements and custom elements that have been successfully defined.

Example

Usage :defined Pseudo-class:

custom-element:not(:defined) {
  border-color: grey;
  color: grey;
}
custom-element:defined {
  background-color: salmon;
  border-color: maroon;
  color: black;
}
/* Display loading message */
custom-element:not(:defined)::before {
  content: "Loading...";
  position: absolute;
  inset: 0 0 0 0;
  align-content: center;
  text-align: center;
  font-size: 25px;
  background-color: white;
}
/* Remove loading message */
custom-element:defined::before {
  content: "";
}

Try It Yourself

CSS Syntax

:defined {
  css declarations;
}

Technical Details

Version: CSS4

Browser Support

The numbers in the table specify the first browser version to fully support this pseudo-class.

Chrome Edge Firefox Safari Opera
54 79 63 10 41