Search code examples
htmlhashanchorequivalent

HTML5 - multiple id's on same element? Language dependend id for hash usage?


Two simple questions from HTML5 specification about multiple id's.

Why one element can't have multiple id's? It is important not to duplicate ids, but having a "equivalence relation" between element and id seeme weird. If there is no real reason, and it is opinion based, please just skip it. If there are some reasons (javascript one to one relation, or sth else, please share it with me!).


I'm working on SEO for some page. The page use id's to anchor some points of the page, for example (it is a stupid example, but it is used only to show the context):

<a href="#comment1">Take a look at the first comment</a>

I want the id="comment1" to be multilanguage, and I've got only one universal template. What is more, sometimes the id's are used for styling, and looks like:

<article id="blog_latest">...</article>

However, I want to anchor to that article, using for example address:

http://en.mysite.com/blog#latest_post
http://pl.mysite.com/blog#najnowszy_wpis

What shall I do?


Additional note:

This is strange, but I think, that:

  • id's are often shown in the url - TRUE
  • url must be language dependend - TRUE
  • one element having one id mess it up when using same templates - TRUE

All three of them cannot be true at once... Has someone from W3C missed something, or am I missing something? :)


Solution

  • I think, your first assumption is not true. Sure you can use the hash value of the url to scroll to an anchor. Most browsers do that by default and some frameworks (like backbone.js) do the same.

    And that's quite ok! Because it is an anchor and not an id! Anchor and id only share the # notation, but only by chance.

    So, for the core of your question, you may (and possibly should) use different anchors for language dependent variants of a page and use these anchors in your DOM (as anchors, not ids!)