Back to Developer Roadmap

Id Vs Class

src/data/question-groups/frontend/content/id-vs-class.md

4.0537 B
Original Source

An id is a unique identifier for a single HTML element. A class is a reusable identifier that can be applied to multiple elements.

You’d want to use an id when you need to address a single element either through CSS or JavaScript. And you’ll want to use a class when you need to address a group of DOM elements.

In CSS:

  • #id selects a specific element with that id.
  • .class selects all elements with that class.