CSS Structure and Formatting of a CSS Rule Multiple Selectors


Example

When you group CSS selectors, you apply the same styles to several different elements without repeating the styles in your style sheet. Use a comma to separate multiple grouped selectors.

div, p { color: blue }

So the blue color applies to all <div> elements and all <p> elements. Without the comma only <p> elements that are a child of a <div> would be red.

This also applies to all types of selectors.

p, .blue, #first, div span{ color : blue }

This rule applies to:

  • <p>
  • elements of the blue class
  • element with the ID first
  • every <span> inside of a <div>