The good intentions were there but in the HTML and Accessibility world, less is sometimes more.
Bad code
<label for="textinput">First name</label>
<input type="text" id="textinput" aria-label="First name" placeholder="First name" title="First name">
Issues and how to fix them
- The
aria-label
,placeholder
, andtitle
attributes all provide the same informaton ("First name"), leading to the screenreader reading the same text multiple times. - The
aria-label
is unnecessary since the input is already correctly labeled by the<label>
element.<label>
elements should be preferred toaria-label
since they are also visible to sighted users. - The
title
attribute is not needed here, as the label and placeholder already convey the necessary information. Using title in this context adds unnecessary complexity. - The
placeholder
text should provide a hint / example to the user what kind of input is expected, it should not act as a label or contain the same content.
Good code
<label for="textinput">First name</label>
<input type="text" id="textinput">