HTMLs Tutorial

HTML Tutorial HTML Tags HTML Basic Tags HTML Attributes HTML Elements HTML Formatting HTML Text Format HTML body tag HTML samp tag HTML script Tag HTML section tag HTML select tag HTML source tag HTML span tag HTML strike tag HTML strong tag HTML style tag HTML sub tag HTML summary tag HTML sup Tag HTML svg tag HTML table tag HTML u tag HTML Headings HTML Paragraphs HTML wbr tag HTML Anchor HTML Image HTML Lists HTML Ordered List HTML Unordered List HTML Form HTML Form input HTML with CSS HTML Layouts HTML References HTML Frames HTML Links Fieldset Tag in HTML Basic HTML Tags Br Tag in HTML Free HTML Templates How to Create a Table in HTML HTML Calendar HTML Card HTML Cellspacing HTML Center Image HTML Checkbox Read-only HTML Cleaner HTML Code for a Tab HTML Comment HTML Compiler HTML Nested Forms HTML Overlay Text on the Image HTML Select Option Default HTML Snake Game HTML Subheader HTML Tab Character dd Tag in HTML How Many HTML Tags are There HTML Align Tag HTML Responsive HTML Tab Code HTML Table Alternate Row Color HTML Table Fix Column Width Contact HTML DL Tag in HTML How to Insert Image in HTML HTML Background Color HTML Dark Mode How to Convert HTML to PNG HTML Data Toggle HTML Email Template HTML Font Color HTML Font Family ID and Class in HTML HTML Tab Space HTML Tab Tag HTML Itemprop HTML Itemscope HTML Form Design HTML Input Only Numbers HTML Textarea HTML to JPG HTML to Markdown Python li Tag in HTML MDN HTML What is the Correct HTML for Making a Hyperlink? What is the Root Element of an HTML Document How to Make a Box in HTML How to Save HTML Files in Notepad How to Align Text in HTML How to Change Font Color in HTML? How to Change Font Size in HTML How to Change Image Size in HTML How to Create a HTML Page How to Create a Link in HTML File? How to Create an HTML File? HR Tag in HTML HTML Base Tag HTML Default Attribute HTML Hyperlink HTML Indent HTML Injection Payloads HTML Input Numbers Only HTML Roadmap HTML Row Height HTML Schedule HTML Space HTML Tab HTML vs HTTP HTML5 API HTML5 Video HTML Collection to Array Text Area in HTML

HTML5 Advance

HTML5 Tutorial HTML5 Tags HTML Button Tag HTML canvas Tag HTML caption Tag HTML City tag HTML Tag HTML5 SVG HTML Event Attribute HTML5 Audio HTML5 Youtube HTML5 Button Tag HTML5 Tags

Misc

How to add JavaScript to HTML How to change font in HTML How to change text color in HTML HTML Date HTML Hide Element HTML Nested Table HTML Reset Button What does HTML stand for? HTML Background Image HTML Tag Div Tag in HTML How to insert Image in HTML How to create a link with no underline in HTML How to insert spacestabs in text using HTMLCSS HTML tag HTML Code HTML Tag HTML Canvas Design a tribute page using HTML and CSS What is a Container tag Font tag in HTML Difference between HTML and DHTML Empty Tag in HTML HTML Button Link Html Line Break Img src HTML Nested List in HTML Placeholder in HTML TD in HTML HTML Space Code HTML Target Attribute HTML Tag Markup Meaning in HTML Border-Collapse in HTML HTML Onclick Online HTML Compiler Convert HTML to PDF HTML Formatter HTML5 - Web Storage HTTP – Responses Container Tag in HTML DL Tag in HTML Horizontal Rule HTML HTML Tab Text Html Table Cell Background Color HTML Table Cell Color HTML Col Width How Many HTML Tags are There Convert String to Unicode Characters in Python HTML Runner HTML Style Attribute HTML Superscript Attribute HTML tabindex Marquee Tag in HTML HTML Dynamic Form HTML side Tag HTML Pattern Attribute HTML q Tag HTML Readonly Base 64 Encoding in HTML Documents Enhancing Data Portability and Security Evo Cam Web Cam HTML Free code camp HTML CSS How to Add a JS File in HTML? How to Add Picture in HTML How to Add the Logo in HTML? How to Add Video in HTML HTML Class Attribute HTML Entities HTML Form Elements HTML Form Templates HTML Marquee Tag HTML Radio Buttons HTML Text box HTML to JSX HTML Tooltip Basic HTML Codes How to Align Image Center in HTML HTML Header Tag HTML Image Tag HTML Next Line

Fieldset Tag in HTML

What is a Fieldset Tag?

In HTML, linked elements within a form are grouped and given a border or visual separator by using the <fieldset> tag. It facilitates form organization and structure by combining related input fields into one group. To give the grouped elements a caption or title, the <legend> element is frequently used with <fieldset>.

HTML <fieldset> tag is used to group the logically related fields/labels contained within an HTML form.

The use of this tag is optional while creating an HTML form, but by using <filedset>, it is easy to understand the purpose of grouped elements of form.

The <legend> tag is used with the <fieldset> element as a first child to define the caption for the grouped related fields.

An HTML element that provides a container with an optional title or caption using the <legend> element and is used to visually group and arrange related form elements. This enhances HTML forms accessibility and structure.

Syntax

The syntax of the fieldset tag is as follows:

<form>

    <fieldset>

        <legend>Contact Information</legend>

        <!-- Your form elements go here -->

    </fieldset>

</form>

Use of fieldset tag

In HTML, related form elements are grouped using the <fieldset> tag. Its main goal is to improve a web form structure and organization. The <fieldset> tag has the following primary uses and advantages:

1.Combining Similar Form Elements

Related form controls like text inputs, radio buttons, checkboxes, and so on can be grouped using the <fieldset> tag.

2. Visual separation

It gives the grouped elements a visual border or separation. To clearly identify which form controls are related to each other, this division is frequently shown as a border surrounding the grouped elements.

3. Accessibility

For users of assistive technologies, accessibility is enhanced using <fieldset> and <legend> elements. The <legend> can be utilized by screen readers, for example, to offer more context regarding the objectives of the grouped elements.

4. Legend for Grouped Elements

Users will find it even easier to understand the purpose of that section when the optional <legend> element inside the <fieldset> provides a title or caption for the collection of form controls.

Attributes of Fieldset Tag

In HTML, the <fieldset> tag has a number of attributes that can be used to change its appearance and behavior. These are the attributes that are often used:

1. Disabled

All of the form controls inside the <fieldset> are turned off when this Boolean attribute is present. When you wish to turn off a collection of form elements conditionally, this is helpful.

2. Form

Names the form element to which the <fieldset> is attached. When the <fieldset> is not a direct child of the <form> element, this attribute is especially helpful.

3. Name

Gives the <fieldset> a name. This feature may come in handy when sending the form data to the server.

Keep in mind that the main function of the <fieldset> tag is to group related form elements. A <fieldset> can optionally have a title or caption provided for the group by using the <legend> tag. When necessary, those mentioned attributes can improve the <fieldset> styling and functionality.

Example 1

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Fieldset Example</title>

  <style>

    /* Optional: Adding some basic styling for better visualization */

    fieldset {

      margin-bottom: 20px;

      padding: 10px;

      border: 1px solid #ccc;

      border-radius: 5px;

    }

    legend {

      font-weight: bold;

    }

  </style>

</head>

<body>

  <form>

    <fieldset>

      <legend>Contact Information</legend>

      <label for="name">Name:</label>

      <input type="text" id="name" name="name"><br>

      <label for="email">Email:</label>

      <input type="email" id="email" name="email"><br>

      <!-- Additional form elements related to contact information can be included here -->

    </fieldset>

    <fieldset>

      <legend>Address Information</legend>

      <label for="address">Address:</label>

      <input type="text" id="address" name="address"><br>

      <label for="city">City:</label>

      <input type="text" id="city" name="city"><br>

    </fieldset>

    <!-- Additional form elements and submit button can be outside the fieldsets -->

    <input type="submit" value="Submit">

  </form>

</body>

</html>

Output:

Fieldset Tag in HTML

Example 2

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Fieldset Example</title>

  <style>

    /* Optional: Adding some basic styling for better visualization */

    fieldset {

      margin-bottom: 20px;

      padding: 10px;

      border: 1px solid #ccc;

      border-radius: 5px;

    }

    legend {

      font-weight: bold;

    }

  </style>

</head>

<body>

  <form>

    <fieldset>

      <legend>Personal Information</legend>

      <label for="firstName">First Name:</label>

      <input type="text" id="firstName" name="firstName"><br>

      <label for="lastName">Last Name:</label>

      <input type="text" id="lastName" name="lastName"><br>

      <label for="age">Age:</label>

      <input type="number" id="age" name="age"><br>

    </fieldset>

    <fieldset>

      <legend>Preferences</legend>

      <label for="color">Favorite Color:</label>

      <input type="text" id="color" name="color"><br>

      <label for="food">Favorite Food:</label>

      <input type="text" id="food" name="food"><br>

    </fieldset>

    <!-- Additional form elements and submit button can be outside the fieldsets -->

    <input type="submit" value="Submit">

  </form>

</body>

</html>

Output:

Fieldset Tag in HTML