Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Universal selector (*)

The universal selector `*` matches elements of any type within the applicable namespace. It adds no specificity itself and can be combined with classes, pseudo-classes, and combinators.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

* { property: value; }
ns|* { property: value; }
*|* { property: value; }
|* { property: value; }

The universal selector * represents an element of any type, not any node: it does not select text or comments. Bare * does not select pseudo-elements such as ::before either; target those explicitly, for example with *::before.

* contributes 0-0-0 specificity; other selector components still count. Without a default namespace, *.marked and .marked match the same elements. An explicit * is not always redundant, though: when a default namespace is declared, :is(*.marked) matches only elements in that namespace, while :is(.marked) imposes no such restriction. Within a compound selector, * must be the first simple selector and cannot appear alongside a type selector; for example, div* is invalid.

Whitespace matters: .demo * selects descendants of .demo at any depth, but not the container itself; .demo > * selects only its children. In the example, both span elements match the first rule, while the more specific second rule makes A blue.

Without a default namespace, * is equivalent to *|* and covers all namespaces. When a default namespace is declared, * is restricted to it. ns|* selects elements in the namespace with the declared prefix ns, while |* selects only elements without a namespace. An undeclared prefix makes the selector invalid.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Universal selector</title>
<style>
  .demo * { color: red; }
  .demo .marked { color: blue; }
</style>
<div class="demo">
  <span class="marked">A</span>
  <span>B</span>
</div>
</html>

Result

A: rgb(0, 0, 255)
B: rgb(255, 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.

Sources