How to use CSS star Selector *

Description

The * selector selects all elements. The * selector can be used to add style for all elements inside another element.


div *

Example


<!DOCTYPE html>
<html>
<head>
<style>
*{<!--from ww w  .j  a v a 2  s  .  c  om-->
    background-color:red;
}
</style>
</head>
<body>
    <h1>heading</h1>
    <p>Paragraph.</p>

</body>
</html>

Click to view the demo

The code above generates the following result.

*

Select all element inside a div


<!DOCTYPE html>
<html>
<head>
<style>
div *<!--from w w w  . jav a2s  . co  m-->
{
    background-color:red;
}
</style>
</head>
<body>
   <h1>header</h1>

   <div>
    <p>paragraph in a div.</p>
   </div>
 
   <p>Outside div.</p>

</body>
</html>

Click to view the demo

The code above generates the following result.

*




















Home »
  HTML CSS »
    HTML CSS Reference »




HTML Tag Reference
CSS Reference
CSS Selector Reference
Encoding Reference