For example, if I write:
background-color: black;
color: white;
or
color: white;
background-color: black;
Is there any difference between the two and should I care about order?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No. You can write them in any order. In the case of duplicates within the same selector, the last rule wins.
When dealing with multiple selectors, rules that come later will override earlier rules, unless the earlier selector is more specific.
For example, this code will turn all your paragraphs green:
While this code will turn all your paragraphs red, because the first selector is more specific.
While the order of rules within a selector may not matter, I would take care to write them in a predictable order (position rules before sizing rules before colouring rules, for example) simply to make your CSS consistent and slightly more pleasant to maintain.