DEV Community

Discussion on: Do you still use IDs for unique elements?

Collapse
 
alohci profile image
Nicholas Stimpson

There are, at my last count, 11 different uses of id attributes in HTML, only one of which is their use in CSS selectors. The other 10 require the id to identify a single element within the document.

For CSS selectors, omitting using id selectors when appropriate to do so, means missing out on some of the power that specificity brings to you.

Collapse
 
keogami profile image
keogami

Examples please

Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️
  • The already mentioned ID-Selector
  • Fragment Identifiers in URLs
  • Input-Label matching
  • Chrome creates a variable for each element with an ID for easier debugging
  • document.getElementById

to name a few