Best practices associated with class vs id:

When I frist started looking at the best use of class versus id in css I was a little bit confused...like why can't I use the id's I define anywhere I want? And what does class have to do with this, isn't that something you are born with? Apparently not. A class within css is like a keyword or group of keywords that can be used to tag different html properties, ocne this has been done a set of rules or definitions is then applied to that tagged piece of html.

Then I learned id's work similar to class - a keyword that then applies a set of rules to whatever html element it is tagged to, except an id can only be used once whereas a class can be applied many times. So why can't I use them interchangeably? Well the reason is that your code will fail any validation test if it finds an id has been used more than once. The way I started to think about them is an id is like your passport or drivers license it is unique to you and no one else has that (unless you have been victim to identity theft). Class is subjective and something everyone can have, which is why class can apply to multiple html elements but id is unique to only one.

.page-bg-color { background-color: #b2b4b2; } This line of code line is how a class is defined in css, notice the keywords I have chosen begin with the "." - this is what makes it a class. #title-text { color: blue; } This is how you define an id in css, notice the "#" at the begining - again this is what makes it an id. Now if you were to see these in action, tagging an html element you would find the following, as you can see the class and id have both been applied to the paragraph tag (without the # or .): id & class example