List all elements or use *?

In the project “Healthy Recipes”
Learn CSS: Selectors and Visual Rules | Codecademy

The last prompt is to

 Finally, let’s make the font Helvetica instead of the default Times New Roman. Instead of writing multiple selectors to apply the `font-family` property, write a selector that applies a `font-family` attribute to all text at once.

The selector should target the `h1` , `h2` , `p` , and `li` elements.

To change their font, include this line of code inside the curly braces: font-family: Helvetica;

I used the * to select all text but noticed in the hints it reads

You can add the same styles to many elements by separating the selector targets with commas:

element1, element2, ... {
 
}

Is using * not best practice or is it just preference?

I would personally say it’s mostly just preference, and it looks like that example was aimed at just getting you to practise that method of using selectors. In my opinion using the universal selector would be fine here seeing as the intention is to apply to every since peice of text on the page (for example it would be a lot of different elements to write out if you more than just those two header types/other text-based elements on the page)

That said, it’s generally good when it comes to selectors to be as specific as possible, to make debugging easier and prevent styles from being applied where they shouldn’t.

3 Likes