Grouping Selectors in CSS
Sometimes the following situation may arise: you need to do the same thing with different tags, for example, color all headings h2, h3 and paragraphs red. In this case, you will have to write something like this:
h2 {
color: red;
}
h3 {
color: red;
}
p {
color: red;
}
However, there is a way to make it a little shorter: tag selectors can be combined with commas and the CSS code will be applied to all of them at once. The code above can be rewritten shorter as follows:
h2, h3, p {
color: red;
}
Simplify your code by using selector grouping:
h1 {
text-align: center;
}
h2 {
text-align: center;
}
h3 {
text-align: center;
}