React warns about for, class or stroke-width copied from HTML
Fix it fast
Most common cause, 1 of 3for and class pasted from HTML
Rename the props.
<label htmlFor="email" className="field-label">Email</label>
<input id="email" name="email" type="email" />Short answer
Invalid DOM property `for`. Did you mean `htmlFor`? means a JSX prop uses the HTML attribute name where React DOM expects the DOM property name: htmlFor for for, className for class. HTML or SVG spellings such as tabindex or stroke-width, typed or spread in, trigger the same warning. Rename each prop as suggested. Applies to React 18 and 19.
Which cause do you have?
Search the components for HTML spellings. A hit on for or class points to cause 1, a hit on another attribute to cause 2, and no hit at all while the warning keeps coming points to cause 3, a spread object. React 18 prints the same text with Warning: in front; React 19 drops that prefix.
grep -rnE " (for|class|tabindex|readonly|maxlength|stroke-width|xlink:href)=" src/Then find the line you see in this list and open its fix:
- 1for and class pasted from HTML
The warning names for or class, and the search finds <label for=...> or class=... in a .jsx or .tsx file - 2Other HTML or SVG attribute spellings
The warning names tabindex, readonly, maxlength, autocomplete, stroke-width or xlink:href, often inside an icon or SVG pasted from a design tool - 3The prop arrives through a spread object
The search finds no for= in the file, but the element spreads an object such as {...labelProps} built from JSON, a CMS or a form schema
What does the error look like?
Invalid DOM property `for`. Did you mean `htmlFor`?Warning: Invalid DOM property `for`. Did you mean `htmlFor`?Invalid DOM property `class`. Did you mean `className`?Invalid DOM property `stroke-width`. Did you mean `strokeWidth`?
Cause 1 of 3
for and class pasted from HTML
You seeThe warning names for or class, and the search finds <label for=...> or class=... in a .jsx or .tsx file
Check
Invalid DOM property `for` appears because React reads JSX props as DOM property names, and the property behind a label's for attribute is htmlFor, just as class becomes className. React DOM keeps a table of these standard names and warns when a prop equals one of them in lowercase but is spelled another way.
grep -rnE " (for|class)=" src/Fix
Rename the props. React still writes for and class into the HTML it renders, so each label stays linked to its input.
<label htmlFor="email" className="field-label">Email</label>
<input id="email" name="email" type="email" />Verify
Reload the page in development: the warning is gone and the rendered label carries for="email".
document.querySelector('label[for="email"]') !== nullConfirmed by react.dev
Cause 2 of 3
Other HTML or SVG attribute spellings
You seeThe warning names tabindex, readonly, maxlength, autocomplete, stroke-width or xlink:href, often inside an icon or SVG pasted from a design tool
Check
The same Invalid DOM property warning fires for any prop whose lowercase form is in React DOM's list of standard names while its spelling differs. That list maps tabindex to tabIndex, readonly to readOnly, maxlength to maxLength, autocomplete to autoComplete, stroke-width to strokeWidth and xlink:href to xlinkHref, which is why pasted SVG markup sets it off so often.
grep -rnE " (tabindex|readonly|maxlength|autocomplete|stroke-width|xlink:href)=" src/Fix
Use the name the warning suggests, in camelCase. ARIA attributes are the exception that keeps the HTML spelling, so aria-label stays aria-label.
<input tabIndex={0} readOnly maxLength={40} autoComplete="email" aria-label="Email" />
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 12h16" stroke="currentColor" strokeWidth={2} />
</svg>Verify
After a reload the console has no Invalid DOM property line for the component.
grep -rnE " (tabindex|stroke-width|xlink:href)=" src/ | wc -lConfirmed by raw.githubusercontent.com
Cause 3 of 3
The prop arrives through a spread object
You seeThe search finds no for= in the file, but the element spreads an object such as {...labelProps} built from JSON, a CMS or a form schema
Check
React validates the props a DOM element finally receives, not the text of the JSX, so a key named for inside an object spread onto <label> raises the same warning as typing it by hand. Form builders that store plain HTML attribute names in their config are the usual source.
grep -rn "{\.\.\." src/components/Field.jsxFix
Rename the keys before spreading, in one small helper that every generated element uses.
const HTML_TO_REACT = { for: 'htmlFor', class: 'className', tabindex: 'tabIndex' };
function toReactProps(attrs) {
return Object.fromEntries(
Object.entries(attrs).map(([key, value]) => [HTML_TO_REACT[key] ?? key, value]),
);
}
<label {...toReactProps(field.labelAttrs)}>{field.label}</label>Verify
The helper returns htmlFor for a for key, and the console stays quiet when the form renders.
console.log(toReactProps({ for: 'email' })); // { htmlFor: 'email' }Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Keep attribute names that come from a CMS or a schema in one mapping helper, so a new field is renamed in one place.
- When pasting SVG from a design tool, rename the hyphenated attributes in the same commit and leave aria-* names as they are.
- Open the development console once after adding pasted markup; the warning names the exact prop and its React spelling.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: TaxiDex, QistLock, Taskvare.