LearnThatStack Ace your next interview
CSS3 · question
Question 5 of 110

How does the universal selector (*) work and when should you use it?

beginner
← All CSS3 questions
Re-explain

The universal selector * matches every element. On its own it adds nothing to specificity. In your own stylesheet, any type, class or ID rule for the same property overrides a bare *. Its two common uses are a reset at the top of a stylesheet and a rule for everything inside a container.

/* Reset all margins and padding */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Target all descendants */
.container * {
  font-family: Arial, sans-serif;
}

The reset zeroes the browser's default spacing and switches every box to border-box. It wins over browser defaults because author styles beat them whatever their specificity. Because * does not match pseudo-elements, resets often list *, *::before, *::after.

Use it sparingly, because it can affect performance and override styles you did not intend. It sets the value directly on each element, which beats any value that element would inherit. And .container * has the class's specificity, so it also beats type rules such as code { font-family: monospace; } inside the container.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the CSS3 cheatsheet.

← Back to all CSS3 questions
Pro · $10/mo

95 of 110 CSS3 answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime