Modern Option

Note: it may not be compatible with older browsers:

.live_grid :is(h1,h2,h3,h4,h5) {
    /* style here */
}

See here for more information about :is(): https://developer.mozilla.org/en-US/docs/Web/CSS/:is

Standard Option:

If you want to style all the headers in that class, you have to do it like this (which could also be done without the line breaks). Notice each selector has .live_grid in it:

.live_grid h1,
.live_grid h2,
.live_grid h3,
.live_grid h4,
.live_grid h5,
.live_grid h6 {
    /* style here */
}

When you comma separate things, they're independent of each other - hence the need to reference the class again.

For example:

#myDiv1, .live_grid, #myDiv2 {
    color: blue;
}

This would set the text-color for everything in the #myDiv1 element, everything in the #myDiv2 element, and everything in the .live_grid element to having text color blue.

This also explains the reason your CSS is matching all the headers - you're referencing them individually, separated by commas - there is no selector for their containing element(s).


CSS pre-processor option

Or, you can always go with something like LESS or SASS which allows you to write nested rules something like this:

#live_grid {
    h1, h2, h3, h4, h5, h6 {
        /* style here */
    }
}

Custom class option

Lastly, you could add a class to all of your headers and just refer to that class:

<-- HTML -->
<h1 class="custom-header">Title of Blog Post</h1>
<h2 class="custom-header">Subtitle of Blog Post about Pizza</h2>

/* CSS */
.custom-header {
    /* style here */
}
Answer from Dave on Stack Overflow
🌐
W3Schools
w3schools.com › css › css_combinators.asp
CSS Combinators
A combinator is something that defines the relationship between two or more selectors. A CSS selector can contain more than one selector.
🌐
ThoughtCo
thoughtco.com › grouping-multiple-css-selectors-3467065
Grouping Multiple CSS Selectors in One Style Property
May 18, 2025 - Learn how grouping CSS selectors simplifies your stylesheets and allows you to style multiple elements without needing additional attributes.
Discussions

Multiple CSS selectors
Because you didn't put any commas in there. p.apple.banana means p tag and apple class and banana class. You're looking for p.apple, p.banana. More on reddit.com
🌐 r/css
4
2
March 6, 2023
How can I set up my CSS so that it will correctly apply to multiple selectors?
I think I understand what you are asking for. First, the reason you are getting red for the final box is because there is a typo after the .members section. Its a stray bracket ] instead of a brace } If you want to assign a color to an element that has 2 classes, you need to declare it like this: .members.youth{ background-color:purple; } .members, .youth is saying all .members and all .youth elements will inherit these styles. Heres a great read on the MDN to read more about it. https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors Good luck! More on reddit.com
🌐 r/css
2
0
August 7, 2024
Help me with multiple selectors
hi I just can’t understand why I have to use multiple selectors can anyone explain that to me with this challenge as an example. also, can anyone tell me why header and footer have been so used as selectors More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
November 8, 2021
In CSS, using a selector with multiple elements on page...
Dylan Carter is having issues with: okay so this isn't necessarily in the video but hypothetically... lets say I have multiple paragraphs, using the p element of course, on... More on teamtreehouse.com
🌐 teamtreehouse.com
2
December 24, 2015
Top answer
1 of 10
65

Modern Option

Note: it may not be compatible with older browsers:

.live_grid :is(h1,h2,h3,h4,h5) {
    /* style here */
}

See here for more information about :is(): https://developer.mozilla.org/en-US/docs/Web/CSS/:is

Standard Option:

If you want to style all the headers in that class, you have to do it like this (which could also be done without the line breaks). Notice each selector has .live_grid in it:

.live_grid h1,
.live_grid h2,
.live_grid h3,
.live_grid h4,
.live_grid h5,
.live_grid h6 {
    /* style here */
}

When you comma separate things, they're independent of each other - hence the need to reference the class again.

For example:

#myDiv1, .live_grid, #myDiv2 {
    color: blue;
}

This would set the text-color for everything in the #myDiv1 element, everything in the #myDiv2 element, and everything in the .live_grid element to having text color blue.

This also explains the reason your CSS is matching all the headers - you're referencing them individually, separated by commas - there is no selector for their containing element(s).


CSS pre-processor option

Or, you can always go with something like LESS or SASS which allows you to write nested rules something like this:

#live_grid {
    h1, h2, h3, h4, h5, h6 {
        /* style here */
    }
}

Custom class option

Lastly, you could add a class to all of your headers and just refer to that class:

<-- HTML -->
<h1 class="custom-header">Title of Blog Post</h1>
<h2 class="custom-header">Subtitle of Blog Post about Pizza</h2>

/* CSS */
.custom-header {
    /* style here */
}
2 of 10
4
.live_grid h1,
.live_grid h2,
...

you get the idea

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Selectors › Selectors_and_combinators
CSS selectors and combinators - CSS | MDN
Multiple pseudo-classes can be combined to create compound selectors. When combining a pseudo-class into a compound selector with a type or universal selector, the pseudo-class must follow the type selector or universal selector, if present. Not all CSS selectors are defined in the CSS selectors ...
🌐
Codecademy
codecademy.com › learn › becp-22-website-development-fundamentals › modules › wdcp-22-learn-css-selectors-and-visual-rules › cheatsheet
Web Development Fundamentals: Learn CSS: Selectors and Visual Rules Cheatsheet | Codecademy
Specificity is a ranking system that is used when there are multiple conflicting property values that point to the same element. When determining which rule to apply, the selector with the highest specificity wins out. The most specific selector type is the ID selector, followed by class selectors, followed by type selectors. In this example, only color: blue will be implemented as it has an ID selector whereas color: red has a type selector. ... The CSS ID selector matches elements based on the contents of their id attribute.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Reference › Selectors › Selector_list
Selector list - CSS | MDN
December 16, 2025 - The CSS selector list (,) selects all the matching nodes. A selector list is a comma-separated list of selectors. When multiple selectors share the same declarations, they can be grouped together into a comma-separated list. Selector lists can also be passed as parameters to some functional ...
Find elsewhere
🌐
Reddit
reddit.com › r/css › multiple css selectors
r/css on Reddit: Multiple CSS selectors
March 6, 2023 -

Suppose, I have two p tags.

<p class="apple orange banana">text</p> <p class="banana">text</p>

CSS: p.apple.banana{ background-color: aquamarine; }

Only, the first p tag with both classes gets a bg color. So, does the browser apply my style on the p tag having both the classes 'apple' and 'banana' and not either of the 2 classes?

I know it is a basic concept but just wanted to clarify this up.

🌐
Mozilla
developer.mozilla.org › en-US › blog › css-not-pseudo-multiple-selectors
How :not() chains multiple selectors | MDN Blog
Have you ever wanted to apply styles to only a few elements and exclude everything else? This is possible in CSS by using the :not() pseudo-class. In this post, we'll take brief look at CSS pseudo-classes, how the :not() pseudo-class works, and how it behaves when multiple selectors are passed ...
🌐
Reddit
reddit.com › r/css › how can i set up my css so that it will correctly apply to multiple selectors?
r/css on Reddit: How can I set up my CSS so that it will correctly apply to multiple selectors?
August 7, 2024 -

I am working with an application where the CSS classes are being automatically generated based on the values of check boxes. The checkbox values are: home, training, members, and youth - always in that order.

The generated class could be any combination of those 4 values, including all 4 at the same time. I want to create CSS that will assign a background color to a DIV based on those classes. For example:

  • class="home" is a white background

  • class="training" is a yellow background

  • class="members" is a red background

  • class="youth" is a blue background

  • any combination with "members youth" will be a purple background

The following is a sample of what I'm playing around with. The last 3 DIVs all have red backgrounds as it is now.

<!DOCTYPE>
<html>
<head>
<title>Test</title>
<style>
div {
  width: 200px;
  height: 200px;
  margin: 10px 0;
  border: 1px solid black;
  text-align: center;
  vertical-align: middle;
  color: black;
}
.home {
  background-color: white;
}
.training {
  background-color: yellow;
}
.members{
  background-color: red;
]
.youth {
  background-color: blue;
}
.members, .youth {
  background-color: purple;
}
</style>
</head>

<body>
  <div class="home">white</div>
  <div class="home training">yellow</div>
  <div class="home training members">red</div>
  <div class="home training members youth">blue</div>
  <div class="home members youth">purple</div>
</body>
</html>
🌐
W3Schools
w3schools.com › css › css_selectors.asp
CSS Selectors
The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element. The CSS rule below will be applied to the HTML element with id="para1":
🌐
CSS-Tricks
css-tricks.com › multiple-class-id-selectors
Multiple Class / ID and Class Selectors | CSS-Tricks
September 28, 2022 - The big point here is that you can target elements that have combinations of classes and IDs by stringing those selectors together without spaces. As we covered above, you can target elements with a combination of ID and class. ... Target an element that has all of multiple classes.
🌐
freeCodeCamp
freecodecamp.org › news › css-selectors-cheat-sheet-for-beginners
CSS Selectors – Cheat Sheet for Class, Name, Child Selector List
September 29, 2022 - Specifically, CSS selectors allow you to select multiple elements at once. They are helpful when you want to apply the same styles to more than one HTML element, because you will no...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Styling_basics › Combinators
Combinators - Learn web development | MDN
October 29, 2025 - You will end up with a descendant selector, and all <li> elements will get a red border. The next-sibling combinator (+) is placed between two CSS selectors. It matches only those elements matched by the second selector that come right after the element matched by the first selector.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Guides › Selectors
CSS selectors - CSS | MDN
January 7, 2026 - The CSS selectors module defines the patterns to select elements to which a set of CSS rules are then applied along with their specificity. The CSS selectors module provides us with more than 60 selectors and five combinators. Other modules provide additional pseudo-class selectors and ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › CSS › Selector_list
Selector list - CSS - MDN Web Docs - Mozilla
October 13, 2025 - The CSS selector list (,) selects all the matching nodes. A selector list is a comma-separated list of selectors. When multiple selectors share the same declarations, they can be grouped together into a comma-separated list. Selector lists can also be passed as parameters to some functional ...
🌐
Codecademy Forums
discuss.codecademy.com › web development
CSS styling with multiple classes - Web Development - Codecademy Forums
March 8, 2024 - Hey! I have a question regarding styling CSS using multiple HTML classes. The lesson teaches us that we can add multiple classes to the target HTML element, then create numerous rulesets that set the styling for specific classes. Eg: HTML Top Vacation Spots CSS .title { color: teal; } .uppercase ...