HTML <fieldset> tag

The <fieldset> tag is used to group related element in an HTML form. It draws a grey or black-border box around the content.

Type: Block Element

Syntax of <fieldset> tag

<fieldset>
  <legend>Name</legend>
  Form elements
</fieldset>

<legend> tag is used as a caption within the <fieldset> element.

Supported Browsers

Tag Chrome Internet Explorer Firefox Safari Opera Mini
<fieldset> Yes Yes Yes Yes Yes

Full code example

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form>
  <fieldset name="groupName" form="formId">
    <legend> Contact Form </legend>
    Name: <input type="text"> <br>
    Address: <input type="text">
  </fieldset>
</form>
</body>
</html>
Run The code »

Output on the browser

Contact Form Name:
Address:

Attributes of <fieldset> tag

Attribute Value Note
disabled disabled It sets unclickable all the input-elements.
form form_id It allows the fieldset belong to multiple form (by giving same id) .
name text It defines the name of the fieldset which is helpful in form processing.

All the attributes are introduced in HTML 5.

Example of using all attributes

<fieldset name="groupName" form="formId" disabled>

Default CSS properties of <fieldset> tag

fieldset {
  display: block;
  margin: 0px 2px 0px 2px;
  padding: 0.5em 0.75em 0.625em 0.75em;
  border: 2px groove;
}