CSS Reference ยท Selectors
The * universal selector
Reference for the CSS universal selector (*): what it matches, its zero specificity, how it works with combinators, box-sizing resets and performance notes.
The universal selector, written as an asterisk (*), matches an element of any type. On its own it selects every element in the document. It is mostly used for broad resets, such as setting box-sizing once for the whole page, and for "everything inside this container" patterns.
The universal selector contributes zero specificity, so any other selector overrides it. That makes it a safe place to put low-priority defaults.
* { box-sizing: border-box; }
Try it
The .panel itself has no outline, because .panel * means "any element that is a descendant of .panel". Remove the space and write .panel* and the rule would no longer parse as intended.
Syntax and arguments
* /* any element */ .card * /* any descendant of .card */ .card > * /* any direct child of .card */ a * /* any element inside a link */ *|* /* any element in any namespace (rare) */
| Form | Description |
|---|---|
* |
Matches every element in the document. |
A * |
Matches every descendant of A. |
A > * |
Matches every direct child of A. |
*.cls / .cls |
Identical. The * is optional before a class, ID, attribute or pseudo-class selector, so people usually leave it out. |
*::before |
Used together with ::after, it adds a pseudo-element to every element. |
Specificity is 0,0,0. Note that * does not match pseudo-elements by itself; *::before is a different selector from *.
Usage notes
- Zero specificity. Because
*never wins a conflict, a* { margin: 0 }reset is overridden by any rule that targets an element, class or ID. This is usually what you want from a reset. - No inheritance chain.
* { color: red }setscoloron each element directly. It is not the same asbody { color: red }: the first rule beats inherited values from anywhere, the second one lets a child inherit and override naturally. Prefer setting inheritable properties onhtmlorbody. - Box sizing reset. A common and sensible use is
*, *::before, *::after { box-sizing: border-box; }, so padding and borders are counted inside the declared width. - Direct children.
.stack > * + *selects every child that has a sibling before it. It is a popular way to add spacing between items without margins on the first item. See the next-sibling combinator. - Performance. Modern browsers match selectors efficiently; a plain
*reset is not a real bottleneck. Avoid very heavy declarations (such as largebox-shadoworfilter) on*, because they are painted on every element. - Does not pierce shadow DOM.
*only matches elements in the same tree scope as the stylesheet. - Forms and replaced elements. Resets like
* { margin: 0; padding: 0; }also strip default spacing from form controls, lists and headings. Re-add what you need deliberately.
Browser support
Supported in every browser.