HTML <legend> Tag

Definition und Verwendung

<legend> Beschreibung des Tags <fieldset> Element Überschrift (Beschriftung).

Weitere Informationen:

HTML DOM Referenzhandbuch:Legend-Objekt

Beispiel

Beispiel 1

Gruppierung relevanter Elemente im Formular:

<form action="/action_page.php">
  <fieldset>
    <legend>Personliche Informationen:</legend>
    <label for="fname">Vorname:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nachname:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-Mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Geburtstag:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

Try It Yourself

Beispiel 2

Feldüberschriften nach rechts ausrichten (CSS verwenden):

<form action="/action_page.php">
  <fieldset>
    <legend style="float:right">Personliche Informationen:</legend>
    <label for="fname">Vorname:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nachname:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-Mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Geburtstag:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

Try It Yourself

Beispiel 3

CSS zur Einstellung verwenden <fieldset> und <legend> Stil:

<html>
<head>
<style>
fieldset {
  background-color: #eeeeee;
}
legend {
  background-color: gray;
  color: white;
  padding: 5px 10px;
}
input {
  margin: 5px;
}
</style>
</head>
<body>
<form action="/action_page.php">
  <fieldset>
    <legend>Personliche Informationen:</legend>
    <label for="fname">Vorname:</label>
    <input type="text" id="fname" name="fname"><br><br>
    <label for="lname">Nachname:</label>
    <input type="text" id="lname" name="lname"><br><br>
    <label for="email">E-Mail:</label>
    <input type="email" id="email" name="email"><br><br>
    <label for="birthday">Geburtstag:</label>
    <input type="date" id="birthday" name="birthday"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>
</body>
</html>

Try It Yourself

Global Attributes

<legend> The tag also supports Global Attributes in HTML.

event attributes

<legend> The tag also supports Event Attributes in HTML.

Default CSS Settings

Most browsers will display the following default values <legend> Element:

legend {
  display: block;
  padding-left: 2px;
  padding-right: 2px;
  border: none;
}

Try It Yourself

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support