Introduction
Group selectors let you style many elements at once. This saves time and keeps your code neat.
Jump into concepts and practice - no test required
Group selectors let you style many elements at once. This saves time and keeps your code neat.
selector1, selector2, selector3 {
property: value;
}h1, h2, h3 {
color: blue;
}p, .note { font-size: 1.2rem; }
button, input[type="submit"] { background-color: green; color: white; }
This page uses a group selector to style h1, p, and elements with class 'highlight' all the same way. They get dark red text and the Arial font.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Group Selectors Example</title> <style> h1, p, .highlight { color: darkred; font-family: Arial, sans-serif; } </style> </head> <body> <h1>Welcome to Group Selectors</h1> <p>This paragraph shares the same style as the heading.</p> <div class="highlight">This div also uses the same color and font.</div> <p>Another paragraph with the same style.</p> </body> </html>
Group selectors help keep your CSS short and easy to read.
Remember to separate selectors with commas and spaces for clarity.
You can group any selectors: tags, classes, or IDs.
Group selectors let you style many elements with one rule.
Use commas to separate selectors inside the CSS rule.
This saves time and keeps your code clean and simple.
h1, p, div { color: red; }h2, .highlight { font-weight: bold; }<h2>Title</h2> <p class="highlight">Important text</p> <div>Normal text</div>
h1, p; div { color: green; }