(HTML question)What is the difference between a id and a class?

I feel like there is a difference, but, honestly, I don’t see it.

It’s for use in CSS. To reference a class you use “.myClass” and to reference an ID you use “#myID”.

1 Like

A class can be assigned to numerous elements, whereas an ID can only be assigned to one element. A class is used to specify multiple elements with the same properties, whereas an ID is used to specify one element with properties.

4 Likes

Well, an ID can still be used by several objects. There is no “rule” on that.

1 Like

True, but it is best to use one ID per object, as referring to that object will be close to impossible otherwise.

1 Like

Technically there is no difference between an ID and a class, but practically there is.

1 Like

NOPE.

Official standard (W3C) for id in HTML states:

The id attribute specifies its element’s unique identifier (ID). [DOM]

The value must be unique amongst all the IDs in the element’s home subtree and must contain at least one character. The value must not contain any space characters.

http://www.w3.org/TR/html5/dom.html#the-id-attribute

1 Like

In JavaScript you would probably be hung by your head, but in CSS I doubt there’s any difference.

1 Like