React error: input is a void element tag and must neither have children
input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`Short answer
React throws this when text or elements sit between input tags, or when children reach an input through spread props. An input accepts no children. Put the caption in a label that wraps the input, or in a sibling element, and keep children out of the props you spread.
Fix it fast
1Find out which cause you have
Search for an input that is written with a closing tag. Every match is a candidate.
grep -rn "</input>" src2Match what you see, then jump to its fix
- 1
The code looks like <input type="radio">Option A</input>.The label text was written inside the input tagFix - 2
The error appears only for your own Radio or Field component, and the call site passes text as its child.A wrapper component spreads its props, including children, onto the inputFix - 3
After removing the children error, React warns about a value or checked prop without onChange.A radio button has checked but no onChangeFix
- 1
What does the error look like?
input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`
Cause 1 of 3
The label text was written inside the input tag
1Check
React's input reference lists children as unsupported: an input does not accept children. In HTML it is a void element.
grep -rn "type=\"radio\"[^/]*>[^<]" src2Fix
Self-close the input and wrap it with a label. A label also makes the caption clickable.
<label>
<input type="radio" name="plan" value="a" checked={plan === "a"} onChange={(e) => setPlan(e.target.value)} />
Option A
</label>3Verify
The page renders and clicking the caption selects the radio button.
# manual check in the browserConfirmed by react.dev
Cause 2 of 3
A wrapper component spreads its props, including children, onto the input
1Check
children is the content between a component's tags. If the wrapper does {...props} on the input, that content goes to the input too.
grep -rn "<input {..." src2Fix
Take children out of the props and render it next to the input.
function Radio({ children, ...rest }) {
return (
<label>
<input type="radio" {...rest} />
{children}
</label>
);
}3Verify
The component renders its caption beside the radio button with no error.
# manual check in the browserConfirmed by react.dev
Cause 3 of 3
A radio button has checked but no onChange
1Check
A radio that receives a boolean checked prop is controlled and needs an onChange handler. Otherwise use defaultChecked, or readOnly for a read-only field.
grep -rn "checked=" src2Fix
Add an onChange that updates the state, or use defaultChecked for an uncontrolled radio.
<input type="radio" name="plan" value="b" defaultChecked />3Verify
No warning in the console and the selection changes on click.
# manual check in the browser consoleConfirmed by react.dev
How do I stop it coming back?
- Write inputs self-closed and put captions in a label.
- Destructure children in wrapper components before spreading the rest.
- Review pull requests for inputs written with a closing tag.
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 built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fix