HTML-Attribut: for

Das for-Attribut ist ein erlaubtes Attribut für <label> und <output>. Wenn es auf ein <label>-Element angewendet wird, zeigt es das Formularelement an, das durch dieses Label beschrieben wird. Wenn es auf ein <output>-Element angewendet wird, ermöglicht es eine explizite Beziehung zwischen den Elementen, die Werte darstellen, die in der Ausgabe verwendet werden.

Probieren Sie es aus

Verwendung

Wenn es als Attribut von <label> verwendet wird, hat das for-Attribut einen Wert, der der id des Formularelements entspricht, auf das es sich bezieht.

html
<label for="username">Your name</label> <input type="text" id="username" />

Wenn es als Attribut von <output> verwendet wird, hat das for-Attribut einen Wert, der eine durch Leerzeichen getrennte Liste der id-Werte der Elemente ist, die zur Erstellung der Ausgabe verwendet werden.

html
<input type="range" id="b" name="b" value="50" /> +
<input type="number" id="a" name="a" value="10" /> =
<output name="result" for="a b">60</output>

Beispiele

Siehe Beispiele zur Verwendung auf den Elementseiten für <label> und <output>.

Spezifikationen

Specification
HTML
# attr-label-for
HTML
# attr-output-for

Browser-Kompatibilität

html.elements.label.for

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
for

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

html.elements.output.for

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
for

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support