Hi,
What is grouping in CSS and uses of it ?
Thanks.
Grouping in CSS
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Hemant KumarRank #1,202 · 1.5K reputationPosted Sep 27, 2011, 3:22 AM EDT
Grouping CSS selectors allows you to put the same styles on many different elements without repeating the styles in your style sheet. This means that your style sheet will be smaller and download more quickly.
How to Group CSS Selectors
Separate multiple grouped selectors in the style property by commas. In this example the style will affect the p and div elements:
Any form of selector can be grouped with any other selector. In this example, a class selector is grouped with an ID selector:
And you can group any number of selectors together. In this example, I've grouped four different selectors:
p, .red, #sub, div a:link { color: #f00; }Any Selector Can be Grouped
As you can see from the above examples, any valid selector can be placed in a group. And all elements in the document that match all the grouped elements will have the same style based on that style property.