Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

React error: input is a void element tag and must neither have children

Errorinput 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.

  • Applies to React 19, Next.js 16, Vite 7
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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>" src
  2. 2Match what you see, then jump to its fix

    1. 1The code looks like <input type="radio">Option A</input>.The label text was written inside the input tagFix
    2. 2The 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. 3After removing the children error, React warns about a value or checked prop without onChange.A radio button has checked but no onChangeFix

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\"[^/]*>[^<]" src

2Fix

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 browser

Confirmed by react.dev

Did this fix it?

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 {..." src

2Fix

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 browser

Confirmed by react.dev

Did this fix it?

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=" src

2Fix

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 console

Confirmed by react.dev

Did this fix it?

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:

Related fixes

Web 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 fix

Web 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.