React htmlFor vs for: Why JavaScript keyword conflict

💡React Tip: Why we use "htmlFor" instead of "for" When I started learning React, this confused me. 👉 HTML version: <label for="name">Name</label> <input type="text" id="name" /> 👉 React version: <label htmlFor="name">Name</label> <input type="text" id="name" /> 👉 Why? "for" is a reserved keyword in JavaScript. So React uses "htmlFor" instead. 👉 What it does? It links the label to the input field. Clicking "Name" will focus the input. ✔ Same behavior ✔ Better accessibility Small concept, but important. #ReactJS #JavaScript #Frontend #WebDevelopment

To view or add a comment, sign in

Explore content categories