Should we always specify the ID attribute in HTML?

From https://www.w3schools.com/tags/att_global_id.asp :

In HTML5, the id attribute can be used for any HTML element (it will check on any HTML element, but this is not necessarily useful).

I am making a browser application for internal use, which on one of the pages does not contain CSS or JavaScript that link to any element of the page - just tables.

Should I still specify the id attribute for the elements, although not (not yet needed) to use it? Or is it just better to use identifiers for future use?

+8
html html5
source share
4 answers

Place required elements or attributes in HTML.

You do not need to specify an identifier attribute if it is not required, and you can always add an identifier attribute as needed.

Saving only the necessary elements in html will facilitate reading, cleaning, low size and, therefore, improve performance and speed.

+22
source share

Identifiers are useful if you want to perform end-to-end testing using an infrastructure such as Protractor, since it is very easy to select the desired item. This is not necessary, however, due to CSS attribute selectors. You can select parts of the CSS class in the DOM, even without the presence of an identifier.

Is identifier easier? Of course, but does the page need to be displayed? Not.

+7
source share

No need to add identifiers unless you intend to use them. It will simply add extra bytes to your site for download. I don’t understand why, in your opinion, you need them, the quoted text that you added to your question does not say that you should use them, it just says that they can be used on any element.

+3
source share

No, this is not necessary. This is only necessary if you need to access any control uniquely on a web page.

-2
source share

All Articles