I’m learning in CSS, I am really confused when to use .(dot) and when to use # in CSS file. Sometimes I really wondered which one I should use.
I’m learning in CSS, I am really confused when to use . (dot) and
Share
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.
#You are .Human
While there are many humans, there is only one you. As such,
.is for classes, which can appear over and over in a document.#is for IDs, which are unique to a document.Note the unique identifier for both
div,personAandpersonB. However both elements have classes in common, such as.firstname, and.lastname.Professional Examples
You can see how these are used out in the wild by looking at tools like Modernizr. This feature-detection tool assists you by adding classes to the
<html>element that inform you as to what the device or browser is capable of:Here we see the one unique value for the
<html>element,#modernizrcom. Following, a series of classes that give more general info about the element. This is a clear example of how an element can have only one id, but many classes.Careful with those IDs!
Because these values are completely unique, they can cause you to paint yourself into a corner at times. It’s worth reading Disallow IDs in Selectors to know more about the potential issues with using IDs in your selectors.