CSS universal selector selects all the elements on a page. Therefore, CSS styles applied to a universal selector affects each and every element(including <html>
and <body>
also) on the page.
The universal selector is represented by an asterisk(*)
character.
In the example below, the universal selector(*)
applies the same styles to each and every element on the page. Try it out to see how it works:
Example:
*{ color: red; text-decoration: underline; }
The universal selector can also be used to select all the elements inside a specific element. For example, selecting all the elements inside a <div>
element.
In the example below, the universal selector selects all the elements that are inside the <div>
element and applies the same styles to each of them.
Example:
div * { background: yellow; border: 2px solid blue; padding: 10px; }
CSS Universal Selector Syntax
The universal selector has the following syntax:
*{ CSS styles }
Related Pages
CSS Tutorial: CSS Selectors