DEV Community

loading...

Discussion on: Difference between an ID and a Class in HTML

Collapse
vazsonyidl profile image
vazsonyidl • Edited

Such a grear article, but some additional info: just to emphasise, within a page an id must be unique.

Most important: ids are automatically created as properties on the global window object.

Good to know, that the ids are linkable, so when you have an id=“here” and you visit your webpage as .com#here, the page will be scrolled to there (if neccessary).

An one personal opinion: using ids make the code hard to maintanable, coming from its behaviour. Because it can be applied to only one element, it can not be reused (nor within a page). Additionally, it has higher precedence than the class merhod, so you have to overwrite the applied rules with !important.

Always use classes, no matter what! :)