Skip to content

noVoidElementsWithChildren (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"correctness": {
"noVoidElementsWithChildren": "error"
}
}
}
}

Disallow children on HTML void elements.

HTML void elements, such as <img> and <br>, cannot contain child content or use the children and dangerouslySetInnerHTML properties. Unlike ordinary JSX elements, a void element cannot have a closing tag.

<br>invalid child</br>
code-block.jsx:1:1 lint/correctness/noVoidElementsWithChildren  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ br is a void element tag and must not have children.

> 1 │ <br>invalid child</br>
│ ^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Unsafe fix: Remove the children.

1 │ <br>invalid·child</br>
│ --------------- --
<img alt="some text" children={"some child"} />
code-block.jsx:1:1 lint/correctness/noVoidElementsWithChildren  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ img is a void element tag and must not have children.

> 1 │ <img alt="some text" children={"some child"} />
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Unsafe fix: Remove the children.

1 │ <img·alt="some·text"·children={"some·child"}·/>
│ ------------------------
React.createElement("img", {}, "child");
code-block.js:1:1 lint/correctness/noVoidElementsWithChildren  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ img is a void element tag and must not have children.

> 1 │ React.createElement("img", {}, "child");
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

ℹ Unsafe fix: Remove the children.

1 │ React.createElement("img",·{},·"child");
│ -------
<img alt="some text" />
React.createElement("img", { alt: "some text" });