Explore 100's Of Free Video Tutorials

Keep Learning, Keep Coding & Keep Sharing

CSS

CSS group selector

Notes:

CSS - Group selector / Grouping selectors:
There are situations where different tags may have similar styles
To reduce code redundancy we create group selector

Syntax of CSS rule-set / rule:
selector
{
declaration list;
}

To implement group selector, in place of selector we write comma separated list of selectors

Syntax of group selector:
selector1, selector2, selector3
{
declaration list;
}

Ex:
h3
{
background-color:gray;
color:white;
border:2px solid black;
}

p
{
background-color:gray;
color:white;
border:2px solid black;
}

Instead of writing two separate rule-sets, we can group them to reduce code redundancy

h3,p
{ background-color:gray;
color:white;
border:2px solid black;
}
Note: Comma separated list of selectors is known as Group selector.

Interview Questions:

1. Which symbol indicates group selector in CSS?
a. space
b. plus
c. comma
d. tilde
Answer: c