CSS * Selector

The * (asterisk) selector selects all elements in a document.

The * selector can also select all elements inside another element.

Version

CSS2

Syntax

*{
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      * {
      background-color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>* selector example</h2>
    <div class="example">
      <p id="example1">Lorem ipsum is simply dummy text...</p>
      <p id="example2">Lorem ipsum is simply dummy text...</p>
    </div>
    <p>Lorem ipsum is simply dummy text...</p>
  </body>
</html>

Another example with the * selector:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      div * {
      background-color: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>* selector example</h2>
    <div class="example">
      <p id="example1">Lorem ipsum is simply dummy text...</p>
      <span id="example2">Lorem ipsum is simply dummy text...</span>
    </div>
    <p>Lorem ipsum is simply dummy text...</p>
  </body>
</html>

Browser support

4.0+ 7.0+ 12.0+ 2.0+ 3.1+ 10.0+

Related Resources


Practice Your Knowledge

The * (asterisk) selector selects




Related articles