A simple question: why should we add the id into our HTML tags if they work perfectly well without them? I know that one of their uses is being able to navigate
it is there to help you identify your element in java-script code.the getElementByID function in java-script give the handle of an element with specific ID for you.like this.
var someElement = document.getelementById("someID");
// do whatever with someElement;
I myself also prefer class for styling through CSS but sometimes you need an element to be unique. For accessibility reasons you use id to input elements to "connect" its label to it by using for attribute. And for Javascript it's much simpler to select an element if it has got id attribute.
id attributes in HTMLfor attribute on <label> and <output> elements.<form> elements for the form attribute on form associated elements.itemref attribute.aria-describedby, aria-labelledby and 4 others.<th> elements for the headers attribute on <td> and <th> elements.<menu> elements for the contextmenu attribute.<datalist> elements for the list attribute on <input> elements.<map> elements for the usemap attribute on the <img> and <object> elements.