totn HTML

HTML: <fieldset> tag

This HTML tutorial explains how to use the HTML element called the <fieldset> tag with syntax and examples.

Description

The HTML <fieldset> tag is found within the <form> tag and is used to group related elements in an HTML form. Use a <legend> tag to create a caption for the <fieldset>.This tag is also commonly referred to as the <fieldset> element.

Syntax

In HTML, the syntax for the <fieldset> tag is: (example groups three related elements - Name, Address, Phone Number)

<body>
<form>
  <fieldset>
    <legend>Customer Information</legend>
    Name: <input type="text"><br>
    Address: <input type="text"><br>
    Phone Number: <input type="text">
  </fieldset>
</form>
</body>

Sample Output


Attributes

In addition to the Global Attributes, the following is a list of attributes that are specific to the <fieldset> tag:

Attribute Description HTML Compatibility
disabled Boolean value indicating that the user cannot interact with the controls within the <fieldset> HTML5
form The id value of a form that the fieldset belongs to HTML5
name The name of the fieldset HTML5

Note

  • The HTML <fieldset> element is found within the <body> tag. It is used to group related labels and controls in the <form> tag.
  • Most browsers will render the <fieldset> tag with a black border around it but you can change this behavior with CSS.
  • You can use the <legend> tag to display a caption for the <fieldset>. This caption will be rendered before the related form controls in the <fieldset> and appear to float over top of the top border of the <fieldset>.

Browser Compatibility

The <fieldset> tag has basic support with the following browsers:

  • Chrome
  • Android
  • Firefox (Gecko)
  • Firefox Mobile (Gecko)
  • Internet Explorer (IE)
  • Edge Mobile
  • Opera
  • Opera Mobile
  • Safari (WebKit)
  • Safari Mobile

Example

We will discuss the <fieldset> tag below, exploring examples of how to use the <fieldset> tag in HTML5, HTML 4.01 Transitional, XHTML 1.0 Transitional, XHTML 1.0 Strict, and XHTML 1.1.