What is the point of id's if there are classes

When I’m coding, I often use Id’s and classes. I realized that why should we have id’s when there are classes. I mean, classes do the job of id’s, they can be applied to one or multiple elements. So why have id?

once your page grows, having ids for key elements on your page helps a lot for styling

lets say you have you have a navigation menu at left hand side of your page, giving this element an id means we can style all of the nested elements using #left-nav selector

ids are also used to associate labels with input elements, which helps screen readers (a tool for people with poor vision)

ids are also super useful, because there should only be one id per page, fetching the element with JS becomes a lot easier

you will run into some of the things i just mentioned as you continue the course

2 Likes