FAQ: CSS Visual Rules - Important

This community-built FAQ covers the “Important” exercise from the lesson “CSS Visual Rules”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development
Build a Website with HTML, CSS, and Github Pages

Learn CSS

FAQs on the exercise Important

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Why would one use !important over an ID selector or vice versa? They seem to serve the same purpose. What’s the difference?

1 Like

I’m just going through the course myself as well, but I saw your question and tried applying an id to the h1 heading in this index.html file, and using an id selector to change the color back to white did work.
But I can see a possible answer in that an id selector is only going to apply to one element (the h1 heading in this case). If we had several h1 headings (or whatever element we’re working on) that all needed to be changed back to a white color, we would have to use an individual id and individual id selector for each one since each id is unique.

2 Likes

What makes the style-library.css file (that sets h1 color to yellow) take precedence over the style.css file that sets the h1 color to white with the same selector?

I think I may have sussed out the answer just now though…I was looking at the links to the two stylesheets, and the type and rel attributes in the link elements were identical. So then I tried reversing the two links (putting the link to style-library.css before the link to style.css) and the h1 text changed to white!
So, what I think is going on here, is that the CSS parses the first link (style.css) and follows those rules, which sets the text to white, and then it parses the second linked file and subsequently changes the text of the h1 heading to yellow.
Is that correct?

7 Likes

Would using !important prevent ‘universal dark mode’ or other visual browser plugins from working properly on your webpage?