What is the Universal Selector?

The Universal selector can be denoted by an asterisk (*), which is a special CSS selector that targets all elements on a web page. It applies a style to every element within the specified scope, making it a powerful but broad-reaching selector.

Syntax

/* Applying styles to all elements using the universal selector */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

/* Applying a border to all elements for illustration purposes */
* {
border: 1px solid #ccc;
}

Features:

  • Wildcard Selection: The universal selector selects all HTML elements within its scope.
  • Global Styling: It’s commonly used for global styling resets, normalizing default styles, or applying consistent box-sizing.
  • Specificity Considerations: While powerful, the universal selector should be used judiciously to avoid unintended consequences or conflicts with more specific selectors.

Contact Us