Skip to content

label-has-control

Reports a <label> that names no control: it has no for attribute (a bound [for] counts) and holds no labelable element (<input> that is not hidden, <select>, <textarea>, <button>, <meter>, <output>, <progress>).

A label that is tied to no control labels nothing: clicking it does not focus a field and a screen reader does not read it with one. Add for with the id of the control, or put the control inside the label.

Reported
...
@if (ok) { <div (click)="a()" aria-hidden="true"></div> }
...
<div (mouseout)="a()" (blur)="b()"></div>
<label>Name</label>
<input id="a" /> <label for="a">Name</label> <label [for]="id">Name</label> <label><input /></label>
...
angular:
lint:
rules:
label-has-control: warn # off (default), warn, error
html:
lint:
rules:
label-has-control: warn # off (default), warn, error
svelte:
lint:
rules:
label-has-control: warn # off (default), warn, error
vue:
lint:
rules:
label-has-control: warn # off (default), warn, error

Enabled by the presets: html/angular-eslint-recommended.

Suppress one line with sudsy-disable-next-line label-has-control 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
angular-eslint label-has-associated-control partial no controlComponents or labelComponents options