W3docs

CSS * Selector

The * CSS selector selects all elements. The * selector can also select all elements inside another element. Read about the selector and try examples.

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

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

Version

CSS2 Universal Selector

Syntax

CSS * Selector syntax

* {
  css declarations;
}

Example of the * selector:

CSS * Selector code 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>

Example of the * selector for a <div> element:

CSS * Selector another code 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>

Practice

Practice

What are the types of CSS selectors mentioned on the specified URL?