Tag HTML <fieldset>


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 <fieldset>tag é usada para agrupar elementos relacionados em um formulário.

A <fieldset>tag desenha uma caixa ao redor dos elementos relacionados.


Dicas e Notas

Dica: A tag <legend> é usada para definir uma legenda para o <fieldset>elemento.


Suporte ao navegador

Element
<fieldset> Yes Yes Yes Yes Yes

Atributos

Attribute Value Description
disabled disabled Specifies that a group of related form elements should be disabled
form form_id Specifies which form the fieldset belongs to
name text Specifies a name for the fieldset

Atributos Globais

A <fieldset>tag também suporta os Atributos Globais em HTML .


Atributos do evento

A <fieldset>tag também suporta os atributos de evento em HTML .



Mais exemplos

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 Fieldset


Configurações padrão de CSS

A maioria dos navegadores exibirá o <fieldset>elemento com os seguintes valores padrão:

fieldset {
  display: block;
  margin-left: 2px;
  margin-right: 2px;
  padding-top: 0.35em;
  padding-bottom: 0.625em;
  padding-left: 0.75em;
  padding-right: 0.75em;
  border: 2px groove (internal value);
}