The element, element selector in CSS is used to style all comma-separated elements with the same style.
Syntax:
element,
element {
/* CSS Property */
}
Example 1:
html
<!DOCTYPE html>
< html >
< head >
< title >
element, element Selector
</ title >
< style >
/* Add same CSS property to all comma
separated elements */
h1,
h2,
div,
p {
text-align: center;
}
div,
p {
background-color: green;
color: white;
}
</ style >
</ head >
< body >
< h1 style = "color: green;" >
GeeksforGeeks
</ h1 >
< h2 >element, element Selector</ h2 >
< div >
A computer science portal for geeks.
</ div >
< p >Welcome to geeks classes.</ p >
</ body >
</ html >
|
Output:

Example 2:
html
<!DOCTYPE html>
< html >
< head >
< title >
element, element Selector
</ title >
< style >
/* Add same CSS property to all comma
separated elements */
h1,
h2,
p {
text-align: center;
}
ul,
p {
background-color: green;
color: white;
}
</ style >
</ head >
< body >
< h1 style = "color: green;" >
GeeksforGeeks
</ h1 >
< h2 >element, element Selector</ h2 >
< p >Welcome to geeks classes.</ p >
< div >Different algorithm techniques:</ div >
< ul >
< li >Searching Algorithms</ li >
< li >Sorting Algorithms</ li >
< li >Graph Algorithms</ li >
</ ul >
</ body >
</ html >
|
Output:

Supported Browsers:
- Apple Safari
- Google Chrome
- Firefox
- Opera
- Internet Explorer
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
06 Jul, 2023
Like Article
Save Article