Skip to content

elementChildrenValidity

Reports void DOM elements that have children, which is invalid HTML.

✅ This rule is included in the jsx logical and logicalStrict presets.

Void elements (also called self-closing or empty elements) are HTML elements that cannot have children. These elements, such as <br>, <img>, and <input>, are self-closing by definition and attempting to give them children violates the HTML specification.

<
JSX.IntrinsicElements.br: DetailedHTMLProps<HTMLAttributes<HTMLBRElement>, HTMLBRElement>
br
>text content</
JSX.IntrinsicElements.br: DetailedHTMLProps<HTMLAttributes<HTMLBRElement>, HTMLBRElement>
br
>
<
JSX.IntrinsicElements.img: DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>
img
>Invalid children</
JSX.IntrinsicElements.img: DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>
img
>
<
JSX.IntrinsicElements.input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
input
>
<
JSX.IntrinsicElements.span: DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span
>Not allowed</
JSX.IntrinsicElements.span: DetailedHTMLProps<HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>
span
>
</
JSX.IntrinsicElements.input: DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>
input
>
<
JSX.IntrinsicElements.hr: DetailedHTMLProps<HTMLAttributes<HTMLHRElement>, HTMLHRElement>
hr
>{
const expression: any
expression
}</
JSX.IntrinsicElements.hr: DetailedHTMLProps<HTMLAttributes<HTMLHRElement>, HTMLHRElement>
hr
>;
<
JSX.IntrinsicElements.meta: DetailedHTMLProps<MetaHTMLAttributes<HTMLMetaElement>, HTMLMetaElement>
meta
>
<
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>Content</
JSX.IntrinsicElements.div: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>
div
>
</
JSX.IntrinsicElements.meta: DetailedHTMLProps<MetaHTMLAttributes<HTMLMetaElement>, HTMLMetaElement>
meta
>

This rule is not configurable.

If your application is a rare one that violates HTML standards and places invalid children inside standard elements, this rule may be counterproductive for you.

Made with ❤️‍🔥 around the world by the Flint team and contributors.