In my view it also disturbs in HTML, if you use internal anchors in the page is usually used href="#link"
and in the element that will be anchored the id="link"
.
If you use the id="link"
in various elements its anchor will never be correct, because it will not know to which element you really want to do the anchoring.
Notice that having two anchors bobbing for the same id
they will always point to the first id
<a href="#link">menu 1</a>
<a href="#link">menu 2</a>
<div id="link" style="margin-top: 100vh">div menu 1</div>
<div id="link" style="margin-top: 200vh">div menu 2</div>
The same happens when using the attribute of label
for="meu-btn"
and in the input
the id="meu-btn"
Notice that by clicking on label
she just marks the first checkbox
, for the two of them having the same id
and the labels
point to the same place.
<label for="meu-btn">label1 btn1</label><br><br>
<label for="meu-btn">label2 btn2</label><br><br>
<input id="meu-btn" type="checkbox">btn1<br>
<input id="meu-btn" type="checkbox">btn2
Another example with label
making it to a list <select>
. Notice I try the same id
independent of label
the foco
is always on the same list
<label for="lista">Lista 1</label>
<select id="lista">
<option>Maria</option>
<option>José</option>
<option>João</option>
</select>
<label for="lista">Lista 2</label>
<select id="lista">
<option>123</option>
<option>345</option>
<option>789</option>
</select>
When speaking of semantics and accessibility the element label
is fundamental, so its correct functioning is essential, so it is important to be used in the correct way always linking label and focal element (https://www.w3.org/WAI/tutorials/forms/labels/)
Importance of Ids in the SVG and the accessibility
According to the W3C specification, we should do nothing additional for Svgs other than provide the <title>
and possibly a <desc>
because they should be available for the accessibility API. Unfortunately, browser support is not yet complete (there are bugs reported for Chrome and Firefox for example).
So, to ensure that the person can access the <title>
and <desc>
:
Add the IDs
appropriate to the <title>
and <desc>
:
<title id = "uniqueTitleID">
The title of the SVG </ title>
<desc id = "uniqueDescID">
A longer and more complete description for complex graphics. </ desc>
For this we need unique Ids as the example below:
<svg id="cat"aria-labelledby="catTitle catDesc" role="img">
<title id="catTitle">Título da figura</title>
<desc id="catDesc">Descrição completa do elemento etc.</desc>
<path d="M545.9,695.9c8.........."/>
</svg>
Source: https://css-tricks.com/accessible-svgs/
Well, looking at the Javascript point of view, where we have the function called
document.getElementById()
that returns only one element when we make this call, you can get the idea that the idea ofid
is to be a reference to a single element. Now, the question is very interesting. We have all learned that you can only use oneid
, but we don’t usually know how to explain "Why"– Wallace Maxters
Related or linked may be dup: https://answall.com/q/170451/101
– Maniero
@Maniero to which you replied, about ID and NAME, would probably serve as dup, but would like to keep to have something more objective within the behavior of DOM and "outside" of it, kind about HTML being permissive, but still things break, I will wait for the answers, if it doesn’t go beyond what you’ve already said there I think I’ll consider as dup even, I have an idea formed in my head, but it still doesn’t go very far.
– Guilherme Nascimento
Finally! Now I will be able to mark several ID questions as duplicates!
– hugocsl