The star in css selects everything?

* {
  text-align: center;
  color: blue;
}

I looked it up on google, but I am asking here just for a little more insight and to check my understanding. The code above is just an example to help me ask the question and not an actual problem.

My question is, the * in the code above is a kind of ‘select all’ selector that selects every html element on the page?

It is commonly used in CSS Flexbox and others?

The asterisk (*) selector in CSS is a universal selector that targets all elements in an HTML document. It can be used to apply a style to all elements on a page or to select specific elements within a nested hierarchy of elements.

For example, if you want to set the margin and padding of all elements to zero, you can use the following CSS code

This is the most common usage when it comes to the asterisk

* {
  margin: 0;
  padding: 0;
}

This will set the margin and padding of all elements, including the body, to zero. However, it’s important to note that using the asterisk selector can have performance implications, as it applies the style to every element in the document. Therefore, it’s recommended to use it sparingly and with caution.

Flexbox is the way on how displaying things so it is not associated with the asterisk

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.