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!
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
Cameren Newkirk
1,271 PointsWhy can't I just use div in css? Why do I have to use a id selector?
In the video he just typed
body{ background: orange }
for div he used a id
why can't I just use div instead of wrapper
div{
}
wrapper{
}
1 Answer

andren
28,550 PointsIf there is only one div on the page then the result would be the same, the advantage of assigning an id is that you are guaranteed to only select that specific div regardless of how many div elements are on the page.
When writing CSS rules you shouldn't just consider what will be selected on the current page but how the rule might affect the page in the future as well. Since it is common to place multiple div elements on a page it is generally a bad idea to use it as a sole selector for a rule when you actually just want to style a specific div element on the page.