Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS How to Make a Website CSS: Cascading Style Sheets Take a Mobile-First Approach

Linus Lim
Linus Lim
1,655 Points

In what instance do you use "ID" selector vs the "Div" selector?

So i know there are two ways to select the element in CSS, but what is the difference from one as compared to the other. It seems like I could use DIV selector for all scenarios. What then is the purpose of the ID selector besides being a more shorter and simpler code to type? Or is that the only reason.

2 Answers

Axel McCode
Axel McCode
13,869 Points

The Div tag is mostly used to identify structural sections of a web page, it can also be used to group many elements together. The ID tag is most commonly used to edit a specific element of a page, for example you can use an ID to edit a specific word in a sentence. It is considered best practice to use ID's to edit one element since ID's can only be used to edit a single element per ID name.

Linus Lim
Linus Lim
1,655 Points

Thank for the explanation Axel. That was very clear.