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?


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.


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?


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

I had this same question. Your last paragraph makes sense but the course doesn’t make that clear. Any clarification would be great. Thanks!

…probably since the second link element stands for the recent stylesheet.

I would like to add that while Bootstrap indeed does use a lot of !important it’s unwise to go that way yourself.

You will thank your past self for not making your job harder by not using !important and using specificity instead to style elements in different ways.

If there are multiple stylesheets linked, and they style the same elements, how is it determined which one will take effect?

For example there are two stylesheets style.css and style2.css with the same lines, but different values in them like so:

In style.css
h1 {
color: blue;

And in style2.css
h1 {
color: red;

you can read @giga4696568018 explanation above. Basically whichever stylesheet is mentioned later in the elements will take precedence.

1 Like

Hi, I would like to ask if we link 2 CSS files to our HTML and we have h1 elements in both the CSS files. Which CSS file will be displayed? and why?

Since we can use !important directly in the style.css file, why do we also have a style-library file?

Hey @method5106451323 welcome to the forums.

In this scenario it wants to show you how to make a new style from scrate using the !important syntax. And the point of having multiple style sheets is to keep everything organized. Look at how many the home page of Codecademy has