CSS * Selector

Beginner
⏱️ 6 min read
📚 Updated: Jul 2026
🎯 4 Examples
Universal / All

What You’ll Learn

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.

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.

📝 Syntax

The syntax for the universal * selector is:

syntax.css
* {
  /* CSS properties */
}

Scope it to a container’s descendants:

scoped-universal.css
.container * {
  margin: 0;
  padding: 0;
}

div * {
  box-sizing: border-box;
}
* { } box-sizing .card * margin: 0

Specificity Comparison

SelectorExampleSpecificity
Universal*(0, 0, 0) — lowest
Elementp(0, 0, 1)
Class.intro(0, 1, 0)
Scoped universaldiv *(0, 0, 2)

Syntax Rules

  • * alone matches every element in the document.
  • parent * matches all descendants inside parent, not the parent itself.
  • Universal selector specificity is zero — any other selector overrides it.
  • Ideal for resets: margin, padding, box-sizing.
  • Avoid heavy properties (animations, shadows) on bare * in production.

Related Topics

  • element — style elements by tag name
  • .class — more specific reusable styles
  • :root — global CSS variables
  • box-sizing — often set globally via *
  • element element — descendant combinator

⚡ Quick Reference

QuestionAnswer
Also known asUniversal selector, all selector
What it targetsEvery element (or all descendants when scoped)
Syntax* { }
Specificity(0, 0, 0) — lowest possible
Most common use* { box-sizing: border-box; } reset
Browser supportAll browsers (CSS 1)

When to Use *

The universal selector is best for foundational setup:

  • CSS resets — Remove default browser margins and padding from all elements.
  • Box model fix — Set box-sizing: border-box globally for predictable layouts.
  • Component scoping — Use .widget * to reset styles inside a component only.
  • Font inheritance — Set a base font-family that all elements inherit.
  • Prototype styling — Quick temporary borders on * to debug layout (dev only).

👀 Live Preview

This demo box uses .uni-demo-wrap * to reset margin and padding on all nested elements:

Reset in action

Heading and paragraph have zero default margins thanks to the * rule scoped to this wrapper.

Sample link

Outside this box, normal browser margins still apply.

Examples Gallery

Practice the * selector with CSS resets, box-sizing, scoped universals, and inherited font defaults.

📜 Core Patterns

Apply global resets to every element on the page.

Example 1 — Basic margin and padding reset

Remove default browser spacing from all elements with a single * rule.

universal-reset.css
* {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, sans-serif;
  padding: 1.5rem;
}
Try It Yourself

How It Works

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.

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

.box {
  width: 200px;
  padding: 20px;
  border: 2px solid #2563eb;
}
Try It Yourself

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.

scoped-universal.css
.card * {
  margin: 0;
}

.card {
  padding: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  background: #f8fafc;
}

.card h3 {
  margin-bottom: 0.35rem;
  color: #1e293b;
}
Try It Yourself

How It Works

.card * selects every descendant inside .card but not the card itself. This gives you component-level control without affecting the rest of the page.

Example 4 — Global font-family via *

Set a base font on all elements so form inputs and buttons inherit it too.

universal-font.css
* {
  font-family: system-ui, sans-serif;
}

body {
  color: #334155;
  line-height: 1.6;
  padding: 1.5rem;
}

input {
  padding: 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
}
Try It Yourself

How It Works

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.

💬 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).

⚠️ 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 contextdiv * 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.

♿ 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.

🖥 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 Chrome 1+ · All versions
Full support
Mozilla Firefox 1+ · All versions
Full support
Apple Safari 1+ · All versions
Full support
Microsoft Edge All versions
Full support
Opera All versions
Full support
* universal selector 100% supported

Bottom line: The safest selector for global resets. Use freely in every project.

🎉 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.

💡 Best Practices

✅ Do

  • Use * for margin/padding resets at the top of CSS
  • Include box-sizing: border-box in your reset
  • Scope with .component * for isolated widgets
  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about *

Use these points when writing CSS resets.

5
Core concepts
000 02

Zero specificity

Lowest.

Cascade
box 03

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.

Practice in the Live Editor

Open the HTML editor and experiment with * resets, box-sizing, and scoped .card * patterns.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful