CSS Selector - Universal selector








The * selector selects all elements.

The universal selector does match every element in the document, including the html and body elements.

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

div *

Summary

CSS Version
2

CSS Syntax

* { 
   style properties 
}




Browser compatibility

* Yes Yes Yes Yes Yes

Example

An example showing how to use * CSS selector.

<!DOCTYPE html>
<html>
<head>
<style>
* {<!--   w ww. j  ava 2  s  .co m-->
    background-color:red;
}
</style>
</head>
<body>
    <h1>heading</h1>
    <p>Paragraph.</p>

</body>
</html>

Click to view the demo





Example 2

Select all element inside a div

<!DOCTYPE html>
<html>
<head>
<style>
div *<!--   w ww  .j ava2s . c  o 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