Why should one add ID to their HTML tags?

Uses of id attributes in HTML

  • As a target for a fragment identifier on a URL.
  • As a target on form controls for the for attribute on <label> and <output> elements.
  • As a target on <form> elements for the form attribute on form associated elements.
  • As a target for element references via the microdata itemref attribute.
  • As a target for element references via some ARIA attributes including aria-describedby, aria-labelledby and 4 others.
  • As a target on <th> elements for the headers attribute on <td> and <th> elements.
  • As a target on <menu> elements for the contextmenu attribute.
  • As a target on <datalist> elements for the list attribute on <input> elements.
  • As part of a hash-name reference to <map> elements for the usemap attribute on the <img> and <object> elements.
  • As an identifier of an element in a CSS selector
  • As an identifier of an element for JavaScript processing

Leave a Comment