Menu
Coddy logo textTech

Universal selectors

Lesson 6 of 15 in Coddy's CSS Selectors course.

The universal selector is a special type of CSS selector that selects all elements on a web page. It is denoted by an asterisk (*).

For example, the selector * selects all elements on the page.

Here is an example of how to use a universal selector to style a web page:

* {
  color: red;
  font-size: 2em;
}

This CSS rule will style all elements on the page to be red and have a font size of 2em.

 

When to use universal selectors?

Universal selectors can be used when you want to style all elements on a web page. For example, you could use a universal selector to set the font size of all elements on the page to 16px.

Universal selectors can also be used to style elements that have not been given any other selectors. For example, if you have a web page with a lot of div elements, but you have not given any of them any class or ID attributes, you could use a universal selector to style all of the div elements.

challenge icon

Challenge

Easy
  • Create a web page with two div elements.
  • Do not give any of the div elements any class or ID attributes.
  • Use a universal selector to style all of the div elements to be red and have a font size of 80px.

Try it yourself

<html>
<head>
  <title>Universal Selector Exercise</title>
  <style>
    /* CSS Code goes here */
  </style>
</head>
<body>
 
</body>
</html>

All lessons in CSS Selectors