Course contentsShow
← Web Development
Lesson 130 of 2,9823. CSS FundamentalsFree lesson

The Universal Selector and Its Uses

Understand when and how to use * selector effectively, including common reset patterns.

The Universal Selector and Its Uses

You'll learn what the * selector is and when to use it to style every element on a page.

What Is the Universal Selector?

The universal selector (*) is a special CSS selector that matches every single element in your HTML document. Think of it like a broadcast message that reaches everyone in a stadium at once—no targeting required.

* {
  margin: 0;
  padding: 0;
}

This rule applies to all <h1>, <p>, <div>, <span>, <form> elements—literally everything.

Common Use: CSS Resets

The most popular use of * is creating a CSS reset, where you zero out default browser styles. Browsers add their own margins and padding to elements, which can cause inconsistencies. Many developers start their stylesheets like this:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

This gives you a clean slate to build upon, ensuring consistent spacing across all browsers.

When to Use It (and When Not To)

Good uses:

  • Resetting margins/padding at the start of your stylesheet
  • Applying box-sizing: border-box universally
  • Quick debugging (temporarily add * { border: 1px solid red; } to see layout boxes)

Be careful:

  • * targets everything, which can have performance implications on massive sites
  • Overly broad resets might remove useful default styles you actually wanted

Combining with Other Selectors

You can use * with descendant combinators:

.container * {
  color: gray;
}

This targets all elements inside .container.

Key Takeaway: The universal selector (*) targets every element on the page and is most commonly used for CSS resets to create consistent styling across browsers.