In my view, it also hinders HTML, if you use internal anchors on the page, you usually use href="#link"
and the element that will be anchored to id="link"
.
If you use id="link"
on several elements your anchor will never be correct, because it will not know which element you really want to do the anchoring.
Note that having two anchors linking to 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 you use the label
for="meu-btn"
attribute and the input
the id="meu-btn"
Note that by clicking label
it only marks the first checkbox
, since the two having the same id
and labels
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
doing is for a <select>
list. Notice that I try the same id
independent of label
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 talking about semantics and accessibility the element label
is fundamental, so its correct operation is imperative, so it is important to be used correctly always linking label and focal element ( link )
Importance of IDs in SVG and accessibility
According to the W3C specification, we should not do anything additional for SVGs other than supplying <title>
and possibly <desc>
because they must 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 <title>
and <desc>
:
Add the appropriate IDs
to <title>
and <desc>
:
-
<title id = "uniqueTitleID">
The SVG title </ title>
-
<desc id = "uniqueDescID">
A longer and more complete description for complex graphs. </ 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: link