CSS | element,element Selector

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


Output:
element-element

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>                    

chevron_right


Output:
element-element2

Supported Browsers: The browser supported by element, element selector are listed below:

  • Apple Safari
  • Google Chrome
  • Firefox
  • Opera
  • Internet Explorer


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.