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 CSS Basics (2014) Basic Selectors Class Selectors

ID selector for multiple pages?

Can an ID selector in css file apply to multiple pages? Say if you have a standard section in your html files of <header id = "top"> for every page of your website, can you use id selector here? Or in this case, a class would be better?

4 Answers

Máté Végh
Máté Végh
25,607 Points

It's perfectly okay to use the same ID on different pages, just make sure you don't use the same ID for different elements inside one page.

Its fine to use them if they are different pages. However on the same page, id should be unique. If you want to label different elements with the same attribute use classes. multiple elements can has the same class.

Mitchell Springer
Mitchell Springer
2,576 Points

IDs should typically be used once. If it's something that is going to repeat on multiple pages, you should use a class.

Demauri Portis
Demauri Portis
4,809 Points

From my knowledge, classes can be repeated throughout html while IDs are used just once.