{"record":{"id":"5d56d1a9ecf248fd","repo":"facebook/react","slug":"137","errorCode":"137","errorMessage":"${tag} is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`.","messagePattern":"(.+?) is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML`\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-dom-bindings/src/client/ReactDOMComponent.js","lineNumber":1162,"sourceCode":"      for (const propKey in props) {\n        if (!props.hasOwnProperty(propKey)) {\n          continue;\n        }\n        const propValue = props[propKey];\n        if (propValue == null) {\n          continue;\n        }\n        switch (propKey) {\n          case 'src':\n            hasSrc = true;\n            break;\n          case 'srcSet':\n            hasSrcSet = true;\n            break;\n          case 'children':\n          case 'dangerouslySetInnerHTML': {\n            // TODO: Can we make this a DEV warning to avoid this deny list?\n            throw new Error(\n              `${tag} is a void element tag and must neither have \\`children\\` nor ` +\n                'use `dangerouslySetInnerHTML`.',\n            );\n          }\n          // defaultChecked and defaultValue are ignored by setProp\n          default: {\n            setProp(domElement, tag, propKey, propValue, props, null);\n          }\n        }\n      }\n      if (hasSrcSet) {\n        setProp(domElement, tag, 'srcSet', props.srcSet, props, null);\n      }\n      if (hasSrc) {\n        setProp(domElement, tag, 'src', props.src, props, null);\n      }\n      return;\n    }","sourceCodeStart":1144,"sourceCodeEnd":1180,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-dom-bindings/src/client/ReactDOMComponent.js#L1144-L1180","documentation":"<img> is a void element: it can never contain DOM children. In setInitialProperties' special img fast-path (which orders src/srcSet last to avoid double-fetching), any non-null children or dangerouslySetInnerHTML prop throws. The check runs before the browser-quirk handling, on the initial mount only.","triggerScenarios":"<img>{loader}</img> or <img {...props} /> where props contains a non-null children key; passing dangerouslySetInnerHTML on img; conditional children rendered inside an img tag.","commonSituations":"Copy-pasting HTML like <img>icon text</img>; component wrappers spreading arbitrary props onto img; JSX auto-inserting children via components that always render props.children inside their tag; accessibility attempts to put caption text inside the image tag.","solutions":["Move the content out: render <img /> self-closed and put text/caption in a sibling element","Use alt (or aria-label on a wrapper) for accessible description instead of children","In generic wrappers, destructure children out before spreading onto void tags: const {children, ...rest} = props; <img {...rest} />","For decoration use CSS background-image instead of child content"],"exampleFix":"// before\n<img src={url}>{caption}</img>\n\n// after\n<figure>\n  <img src={url} alt={caption} />\n  <figcaption>{caption}</figcaption>\n</figure>","handlingStrategy":"validation","validationCode":"const VOID_TAGS = new Set(['img','input','br','hr','meta','link','area','base','col','embed','source','track','wbr','param']);\nfunction safePropsFor(tag: string, props: Record<string, unknown>) {\n  if (!VOID_TAGS.has(tag)) return props;\n  const {children, dangerouslySetInnerHTML, ...rest} = props;\n  if (children != null || dangerouslySetInnerHTML != null) {\n    console.warn(`<${tag}> is void; dropping children/html`);\n  }\n  return rest;\n}","typeGuard":"const isVoidTag = (tag: string) =>\n  VOID_TAGS.has(tag.toLowerCase());","tryCatchPattern":null,"preventionTips":["Write void elements self-closed","Generic element renderers must strip children for void tags","Put captions/alt text in siblings or attributes, never inside the img"],"tags":["react-dom","void-element","img","children","props-validation"],"backgroundTag":"void-element-children","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}