HTML Fieldset TagHTML <fieldset> tag groups the logically related fields/labels in an HTML form. Using this tag is optional while creating an HTML form, but using the <fieldset> tag makes it easier to understand the purpose of the grouped elements of the form. The <legend> tag is used with the <fieldset> element as a first child to define the caption for the grouped related fields. This combination of <fieldset> tag and <legend> tag helps organize and structure the form, which makes it more understandable and accessible to users. Syntax of <fieldset> TagThe above syntax contains :
The form elements are placed between <fieldset> tag. Syntax of <legend> TagThe above syntax contains :
The caption is written inside the opening tag and closing tag of the <legend> element. Examples of the <fieldset> TagExample 1:We create a "User basic information" group using the <fieldset> tag in this example. Code: Output: As you can see below, the group name is displayed, and a boundary line is drawn around the grouped elements. Example 2In this example, we are creating two groups, which are named "Contact Information" and "Address Information", using the <fieldset> tag. Code: Output: As you can see below, a boundary line is drawn around the two groups. Example 3In this example, we are creating two groups, which are named "Product Details" and "Shipping Details", using the <fieldset> tag. Code: Output: As you can see below, a boundary line is drawn around the two groups. Example 4In this example, we are creating a group named "Your Information" and turning off all form controls within the <fieldset> tag using the "disabled" attribute. Code: Output: As you can see below, a boundary line is drawn around a group, and all form controls have been turned off. AttributesTag-specific attribute:
Global attributes HTML <fieldset> tag supports the global attributes in HTML. Event attributes HTML <fieldset> tag supports the event attributes in HTML. Browser SupportBelow are the browsers that support the <fieldset> tag:
ConclusionIn this article, you have understood the HTML <fieldset> tag with the help of examples and how it is used to group related fields within an HTML form. Next TopicHTML figcaption Tag |