IDs should not convey information?

While working on my tribute page I wondered about attribute naming conventions, particularly ones for ids, and so I took a peek at MDN page on ids.

To my surprise, I found this paragraph:

What does this mean exactly, and why shouldn’t I do it? Does it only refer to names that have corresponding semantic HTML elements, like “header”, “nav” or “section”? I’m guessing it may have something to do with accessibility.

This means that you shouldn’t be relying on the id to communicate information. If all your ids were replaces with random numbers, everything would still work just as well.

2 Likes

Ah, that makes sense. Thanks.

an ID or class does not show up on the web page. You could use any old text or numbers in there and it wouldn’t change anything. It is best practice to call it something that describes the section though, obviously. (I.e. div class=“container”). In theory this could be called anything, but at least you know what you’ve created it for when you call it a container!