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, andtitleattributes all provide the same informaton ("First name"), leading to the screenreader reading the same text multiple times. - The
aria-labelis unnecessary since the input is already correctly labeled by the<label>element.<label>elements should be preferred toaria-labelsince they are also visible to sighted users. - The
titleattribute is not needed here, as the label and placeholder already convey the necessary information. Using title in this context adds unnecessary complexity. - The
placeholdertext 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">