Grouping Selectors


Sometimes you want to apply the same style to many elements.

Grouping selectors help you do this easily and cleanly.

What Is a Grouping Selector

A grouping selector allows you to combine multiple selectors and apply the same styles to all of them.

How Grouping Selectors Work

You write multiple selectors separated by commas.

Now all headings share the same color.

Why Use Grouping Selectors

Grouping selectors help you:

  • Reduce repeated code
  • Keep CSS shorter
  • Make updates easier

Without Grouping

You would have to write the same style many times.

This works, but it is longer and harder to maintain.

With Grouping

One rule can replace all of that.

Much cleaner and easier to update.

Grouping Different Types of Selectors

You can group:

  • Element selectors
  • Class selectors
  • ID selectors

All these elements now share the same style.

Why This Matters for Jobs

Professional developers write efficient CSS.

Grouping selectors helps keep projects clean and maintainable.

Common Beginner Mistakes

  1. Forgetting commas between selectors
  2. Writing duplicate styles instead of grouping

Practice Task

Create a CSS file and:

  • Group all heading selectors
  • Apply the same color to them
  • Group two class selectors and style them

What You Will Learn Next

In the next lesson, you will learn descendant and child selectors.