The CSS * selector — called the universal selector — matches every element on the page. It is most famous for CSS resets that zero out margins and set box-sizing: border-box globally.
*
All elements
Every tag.
01
CSS reset
margin: 0.
02
box-sizing
border-box.
03
Scoped
div *
04
Specificity
(0, 0, 0)
05
Global
Base styles.
Fundamentals
Introduction
The CSS universal selector (*) selects all elements in a document. When you write * { margin: 0; }, every HTML element — from <html> to <span> — receives that style.
It is a powerful tool for applying global defaults and CSS resets, but it should be used thoughtfully. Because it targets everything, heavy styles on * can affect performance on very large pages.
Definition and Usage
The most common real-world use of * is the universal box-sizing: border-box reset, which makes layout math predictable. You can also scope it: .card * affects only elements inside .card, not the whole page.
💡
Beginner Tip
Think of * as “select everything.” It is perfect for one-time resets at the top of your stylesheet, then use element, class, and id selectors for actual design styles.
Browsers add default margins to h1, p, ul, and other elements. The * rule zeros them all at once. You then add intentional spacing on body or specific components.
Example 2 — Universal box-sizing reset
The most popular * pattern — make padding and borders count inside element width.
Total width stays 200px including padding and border.
How It Works
Without border-box, a 200px box with 20px padding and 2px border would overflow its container. Setting it on * ensures every element uses the intuitive box model by default.
📄 Scoped & Inherited
Limit * to a container or set inherited defaults.
Example 3 — Scoped universal: div *
Reset only elements inside a specific container, leaving the rest of the page untouched.
Form elements like input and button do not always inherit font-family from body. Setting it on * ensures every element — including inputs — uses the same typeface.
Tips
💬 Usage Tips
Reset once at the top — Put your * reset as the first rules in your stylesheet.
Always add box-sizing — Pair margin/padding reset with box-sizing: border-box.
Scope when possible — Use .component * instead of global * for isolated widgets.
Layer specific styles after — Follow * with element, class, and id rules.
Avoid decorative styles — Do not set colors, shadows, or animations on bare *.
Debug with borders — * { outline: 1px solid red; } helps visualize layout (remove before shipping).
Watch Out
⚠️ Common Pitfalls
Overuse slows rendering — Heavy styles on every element can impact large, complex pages.
Zero specificity — Any class or id rule overrides *; do not rely on it for important styles.
Unintended inheritance — Properties like color on * cascade to everything, including form controls.
Forgetting scoped context — div * does not select the div itself, only its children.
Replacing component styles — * is for resets, not for building your entire design system.
Third-party widgets — Global * resets can unintentionally affect embedded widgets or iframes.
A11y
♿ Accessibility
Preserve focus styles — Do not reset outline on * without providing alternative :focus styles.
Keep readable defaults — If resetting margins, re-add spacing so content is not cramped.
Form element fonts — Setting font-family on * helps inputs match body text (good for consistency).
Do not hide content — Never use * { display: none; } or similar destructive global rules.
Test keyboard navigation — Ensure focus rings remain visible after any global reset.
🧠 How * Works
1
Write the * rule
You declare * { box-sizing: border-box; } in your CSS.
CSS
2
Browser matches all
Every element in the document (or scoped parent) is selected.
Match
3
Styles apply globally
Reset properties take effect on every matched element.
Render
=
✱
Consistent baseline
More specific selectors layered on top override * where needed.
Compatibility
🖥 Browser Compatibility
The universal * selector has been supported since CSS 1 and works in every browser.
✓ Baseline · CSS 1
Universal support everywhere
The * selector works in Chrome, Firefox, Safari, Edge, Opera, and all legacy browsers without prefixes or fallbacks.
100%Global support
Google Chrome1+ · All versions
Full support
Mozilla Firefox1+ · All versions
Full support
Apple Safari1+ · All versions
Full support
Microsoft EdgeAll versions
Full support
OperaAll versions
Full support
* universal selector100% supported
Bottom line: The safest selector for global resets. Use freely in every project.
Wrap Up
🎉 Conclusion
The CSS * universal selector is a versatile tool for targeting every element on a page. It is especially valuable for CSS resets that normalize browser defaults and set box-sizing: border-box globally.
Use it with care — keep rules lightweight, scope when possible, and layer more specific selectors on top for your actual design styles.
Follow resets with specific element and class rules
Set font-family on * for form consistency
❌ Don’t
Apply heavy animations or shadows to bare *
Remove focus outlines without providing alternatives
Use * as your only styling approach
Set colors globally unless you intend a full theme reset
Leave debug borders on * in production
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about *
Use these points when writing CSS resets.
5
Core concepts
*01
All elements
Universal.
Syntax
00002
Zero specificity
Lowest.
Cascade
box03
border-box
Top use.
Reset
. *04
Scoped
.card *
Pattern
🌐05
100% support
CSS 1.
Compat
❓ Frequently Asked Questions
The * selector matches every element in the document — or every descendant within a scoped parent like div *. It is commonly used for CSS resets that remove default browser margins and padding.
The universal selector has zero specificity: (0, 0, 0). Any element, class, or id selector will override a bare * rule when properties conflict.
Yes. Applying box-sizing: border-box to all elements via * is a widely used pattern. It makes width and height calculations include padding and borders, simplifying layouts.
Yes. Writing .card * or div * selects all elements inside that container only, not the entire page. This is useful for component-scoped resets.
Yes. The universal selector has been part of CSS since the beginning and works in every browser, including all modern and legacy browsers.