Tag HTML <legend>
Exemplo
Agrupe elementos relacionados em um formulário:
<form action="/action_page.php">
<fieldset>
<legend>Personalia:</legend>
<label for="fname">First
name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input
type="text" id="lname" name="lname"><br><br>
<label
for="email">Email:</label>
<input type="email"
id="email" name="email"><br><br>
<label
for="birthday">Birthday:</label>
<input type="date"
id="birthday" name="birthday"><br><br>
<input
type="submit" value="Submit">
</fieldset>
</form>
Mais exemplos de "Experimente você mesmo" abaixo.
Definição e uso
A <legend>
tag define uma legenda para o elemento <fieldset> .
Suporte ao navegador
Element | |||||
---|---|---|---|---|---|
<legend> | Yes | Yes | Yes | Yes | Yes |
Atributos Globais
A <legend>
tag também suporta os Atributos Globais em HTML .
Atributos do evento
A <legend>
tag também suporta os atributos de evento em HTML .
Mais exemplos
Exemplo
Deixe a legenda do fieldset flutuar para a direita (com CSS):
<form action="/action_page.php">
<fieldset>
<legend style="float:right">Personalia:</legend>
<label for="fname">First name:</label>
<input
type="text" id="fname" name="fname"><br><br>
<label
for="lname">Last name:</label>
<input type="text"
id="lname" name="lname"><br><br>
<label
for="email">Email:</label>
<input type="email"
id="email" name="email"><br><br>
<label
for="birthday">Birthday:</label>
<input type="date"
id="birthday" name="birthday"><br><br>
<input
type="submit" value="Submit">
</fieldset>
</form>
Exemplo
Use CSS para estilizar <fieldset> e <legend>:
<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>Personalia:</legend>
<label for="fname">First
name:</label>
<input type="text" id="fname" name="fname"><br><br>
<label for="lname">Last name:</label>
<input
type="text" id="lname" name="lname"><br><br>
<label
for="email">Email:</label>
<input type="email"
id="email" name="email"><br><br>
<label
for="birthday">Birthday:</label>
<input type="date"
id="birthday" name="birthday"><br><br>
<input
type="submit" value="Submit">
</fieldset>
</form>
</body>
</html>
Páginas relacionadas
Referência HTML DOM: objeto de legenda
Configurações padrão de CSS
A maioria dos navegadores exibirá o <legend>
elemento com os seguintes valores padrão:
Exemplo
legend {
display: block;
padding-left: 2px;
padding-right: 2px;
border: none;
}