Skip to content

html-self-closing

Reports an element written in the wrong form for Vue’s style: an HTML element, a component, an SVG or MathML element without content should be self-closed (<div />), a void HTML element should not (<img>). The elements of the file’s root (<template>, <script>) are not reported. Only in .vue files.

Both forms mean the same in a Vue template, and the style puts the empty elements in one shape that is quick to see.

To fix, write the empty element as <div /> and the void one as <img>.

Reported
<template>
<div>
<div></div>
<img />
<img>
<div />
<div>text</div>
<MyCard></MyCard>
<svg><path d="M0"></path></svg>
...
<a v-if="ok" :href="u" @click="go">x</a>
<input v-bind="props" :id="i" v-model="m">
...
angular:
lint:
rules:
html-self-closing: warn # off (default), warn, error
html:
lint:
rules:
html-self-closing: warn # off (default), warn, error
svelte:
lint:
rules:
html-self-closing: warn # off (default), warn, error
vue:
lint:
rules:
html-self-closing: warn # off (default), warn, error

Enabled by the presets: html/eslint-plugin-vue-recommended.

Suppress one line with sudsy-disable-next-line html-self-closing in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
eslint-plugin-vue html-self-closing partial the default options only