
Why <label> and <button> Are Better Than <div> for Forms
Small HTML Choices That Affect Accessibility Many developers focus on JavaScript frameworks and UI styling, but forget that HTML semantics already provide powerful built-in functionality . Two common mistakes are: ignoring the <label> tag in forms using <div> instead of <button> for interactions These decisions affect accessibility, usability, and maintainability . 1. Why <label> Improves Form Accessibility Many forms are written like this: <div> Name <input type= "text" > </div> This works visually, but it creates problems for screen readers. The correct version is: <label for= "name" > Name </label> <input id= "name" type= "text" > Benefits of Using <label> Using <label> provides several improvements: Screen readers correctly associate the label with the input Clicking the label focuses the input Improves form usability for all users Example: <label for= "email" > Email </label> <input id= "email" type= "email" > Now users can click either the text or the input . 2. Why <button> Is B
Continue reading on Dev.to
Opens in a new tab




