This forum is now read-only. Please use our new forums! Go to forums

Close banner
0 points
Submitted by dvd-nis
about 10 years

Using the same ID twice?

The text editor lets me use the exact same ID tag more than once and when I give specific attributes to that particular ID tag in the CSS file, all the elements with that one ID change. Doesn’t this make the functionality of ID exactly the same as the functionality of class?

Answer 536d27d8282ae358b60002b7

6 votes


Submitted by Lucien
about 10 years


dvd-nis about 10 years

Ahhh I see, mainly for javascript purposes. Thanks man

Michael Chase almost 10 years

Thanks for asking this (and answering this). I was thinking the same thing myself.

ddelph almost 10 years

Had the same question.Thanks for the answer

amenthes over 9 years

This is actually an error in the curriculum. You should not use “id” more than once. Usually, nothing will really break, but it’s bad practice.

Zeke Y over 9 years

@Lucien anybody posting a link to CSS Tricks gets an automatic upvote from me :)

mavz over 9 years

how do u add id in h1 for example

Zeke Y over 9 years

@mavs: The same way you do for anything else: <h1 id="id">Text</h1>

Answer 536d6e77282ae3a786000309

3 votes


For good measure, here is the CSS2 page for Selectors on

Document languages may contain attributes that are declared to be of type ID. What makes attributes of type ID special is that no two such attributes can have the same value; whatever the document language, an ID attribute can be used to uniquely identify its element. … The ID attribute of a document language allows authors to assign an identifier to one element instance in the document tree. …

Submitted by Roy
about 10 years

Answer 54dd206086f5523c38000087

0 votes


Using same ID more than once is a bad practice although it might work in many situations.

If you code the same in VB and try, it will throw a warning and automatically change the ID’s so that they are unique.

over 9 years

Answer 55c3302a937676139d00009e

-1 votes


This exercise is wrong then, because it clearly asks from us to use the same ID twice (in french at least) and to apply CSS attributes only once. And when I do it works.

Submitted by Adrien
almost 9 years